Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

I think Craig missed out the negative error for the bill amount

import math

def split_bill(total, number_of_people):
    if number_of_people <= 1:
        raise ValueError("More than 1 person is required to split the bill")
    return math.ceil(total / number_of_people)
try:
    total_due = float(input("What is the total bill? "))
    if total_due <= 0:
        raise ValueError("The bill should more than $0")
    number_of_people = int(input("How many customers are paying this bill? "))
    amount_due = split_bill(total_due, number_of_people)
except ValueError as err:
    print("Oh no! That's not a valid value, please input a number")
    print("({})".format(err))
else:  
    amount_due = split_bill(total_due, number_of_people)
    print("Each person owes ${}".format(amount_due))

I have written this code above in order to fix the error, please tell me if there is anything wrong in my code.

1 Answer

Steven Parker
Steven Parker
243,266 Points

Spotting alternatives and potentially more effective solutions is a good indication of your learning progress and grasp of the material! :+1: