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
Mohit yadav
Python Web Development Techdegree Student 471 PointsStill confused about try method
I still can't understand why the variable defined in try method will return name error in the lecture video?
Mohit yadav
Python Web Development Techdegree Student 471 Pointsdef split_check(total, number_of_people): return math.ceil(total / number_of_people) try: total_due = float(input("What is the total?")) number_of_people = int(input("number of people?')) except ValueError: print("Oh no! That's not a valid value. Try again...") amount_due = split_check(total_due, number_of_people) print("Each person owes ${}".format(amount_due))
Mohit yadav
Python Web Development Techdegree Student 471 PointsI'm not able to find the option to add a snapshot but when I pass any string in this function, it returns name error for total_due and this is explained in the video but I couldn't understand.
Kevin Gates
15,053 PointsFor clarification, when you use the Markdown Cheatsheet to format your code, it will look like this:
def split_check(total, number_of_people): return math.ceil(total / number_of_people) try: total_due = float(input("What is the total?")) number_of_people = int(input("number of people?')) except ValueError: print("Oh no! That's not a valid value. Try again...") amount_due = split_check(total_due, number_of_people) print("Each person owes ${}".format(amount_due))
3 Answers
Mohit yadav
Python Web Development Techdegree Student 471 PointsOh nevermind, I saw the video again carefully and understood what was wrong. Thanks for helping.
Kevin Gates
15,053 PointsI'm glad I could help get you closer. :)
Kevin Gates
15,053 PointsWhen looking at your code formatted,
def split_check(total, number_of_people): return math.ceil(total / number_of_people) try: total_due = float(input("What is the total?")) number_of_people = int(input("number of people?')) except ValueError: print("Oh no! That's not a valid value. Try again...") amount_due = split_check(total_due, number_of_people) print("Each person owes ${}".format(amount_due))
You can see you used the wrong quote to close out this section
int(input("number of people?'))
You should use the double quote:
int(input("number of people?"))
Now your code is formatted correctly:
def split_check(total, number_of_people): return math.ceil(total / number_of_people) try: total_due = float(input("What is the total?")) number_of_people = int(input("number of people?")) except ValueError: print("Oh no! That's not a valid value. Try again...") amount_due = split_check(total_due, number_of_people) print("Each person owes ${}".format(amount_due))
Mohit yadav
Python Web Development Techdegree Student 471 PointsStill gives the name error when passing a string
Kevin Gates
15,053 PointsCan you share a link to the video in question? Your question here isn't linking to it.
Thanks.
Mohit yadav
Python Web Development Techdegree Student 471 Pointshttps://teamtreehouse.com/library/expecting-exceptions At 4:12 when he runs the code for this first time, it gives an error
Kevin Gates
15,053 PointsKevin Gates
15,053 PointsCan you share your code in question, or make a snapshot of your workspace to share so that we can more easily assist you?