Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics Functions and Looping Raising Exceptions

Abdullah Jassim
Abdullah Jassim
4,551 Points

How 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

    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")
    print("Each person owes ${}".format(call))

1 Answer

Steven Parker
Steven Parker
216,165 Points

Right 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.