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

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!