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 trialAli Waris
2,303 PointsIs this way of doing this correct too? Because the one of raising error seem difficult.
import math
def split_check(total, number_of_people):
return math.ceil(total / number_of_people)
try:
total_due = float(input("What is the total? "))
while True:
number_of_people = int(input("How many people? "))
if number_of_people > 0:
break
else:
print("Number of people must be greater than 0. Try again...")
except ValueError:
print("Please enter a valid value. Try again...")
else:
amount_due = split_check(total_due, number_of_people)
print(f"Each person owes {amount_due}")
1 Answer
Steven Parker
231,248 PointsYou didn't provide a link to the lesson, so if the exercise was about how to raise an event in code, this might not be "correct" from the standpoint of the lesson.
But as far as getting the job done of assuring a positive response, this certainly handles it. In programming, there will always be several valid ways to approach any objective. The courses try to teach a variety of techniques so you can choose the best one for each task you might need to accomplish.