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 trialAbdullah Jassim
4,551 PointsHow do I keep repeating the loop until i get an answer? I guess while loop but where do I input it?
import math
def split_check(bill, people):
amt_due = math.ceil(bill // people)
return amt_due
try:
bill = float(input("What is the total bill? "))
people = int(input("How many people are there? "))
call = split_check(bill, people)
except ValueError:
print("Oh no! Try again")
except ZeroDivisionError:
print("Has to be more than 1 person")
else:
print("Each person owes ${}".format(call))
1 Answer
Steven Parker
231,248 PointsRight before the "try" you could put "while true:
", and then indent everything below it to put it inside the loop.
Then after the final "print" you could add a line with "break
" so the loop ends when the calculation is successful.