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 Returning Values

Ethan Martin
PLUS
Ethan Martin
Courses Plus Student 1,883 Points

check_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))

Bruce Röttgers
Bruce Röttgers
18,211 Points

Hey,

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.

1 Answer

Hey 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!