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 trialSeth Marquis
177 Pointshow can I divide 2 inputs then print the answer?
this is what i have now:
cost = input('how much did it cost?') people = input('how many people?')
total = cost / people
print('each person owes {}'.format(total))
2 Answers
Tiffany Greathead
6,613 PointsHi Seth,
You're close. The input function in python takes the input and turns it into a string and strings cannot be divided. You would need to wrap your input function in an int() or float() to make this program work. Ideally, for number of people, you would want to stick to whole numbers and use decimals for totals. Keep up the great work! Hope this helps
benjamind
6,442 PointsAs already stated, you need to convert your Strings into Integer. This could be done right when you take the values or...
cost = int(input("How much did it cost? "))
people = int(input("How many people? "))
total = cost / people
print("Each person owes {}".format(total))
or when you use them:
cost = input("How much did it cost? ")
people = input("How many people? ")
total = int(cost) / int(people)
print("Each person owes {}".format(total))