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 trialEthan Martin
Courses Plus Student 1,883 Pointscheck_please.py
I want to make this interactive but I am having trouble The code will allow the input but after it gets both pieces it spits this out...
Traceback (most recent call last):
File "check_please.py", line 10, in <module>
amount_due = split_check(bill_total, num_people)
File "check_please.py", line 2, in split_check
cost_per_person = total / number_of_people
TypeError: unsupported operand type(s) for /: 'str' and 'str'
Can someone help me understand what this means? Below is my code
def split_check(total, number_of_people): cost_per_person = total / number_of_people return cost_per_person
bill_total = input("How much was your bill? ") num_people = input("How many people will split the bill? ")
amount_due = split_check(bill_total, num_people)
print("If {} people are splitting the bill that totals {}, \neach person will pay {}.".format(num_people, bill_total, amount_due))
1 Answer
jucliofonseca
959 PointsHey Ethan!
The problem is that the function input() (in python3) returns a string (text). Try converting bill_total and num_people to float (number) and it will be solved ;)
bill_total = float(input("How much was your bill? "))
num_people = float(input("How many people will split the bill? "))
Best Regards!
Bruce Röttgers
18,211 PointsBruce Röttgers
18,211 PointsHey,
for future questions: If you click on the Markdown Cheatsheet it shows you how to format your question, including that the code get's shown in the right format.