+ 1
[Solved] What is wrong with my if statement?
money = int(input("")) price = int(input("")) friends = 10 total = price*friends if money >= total: print (str(money-total)) I can't pass the assignment and don't know why. Assignment: Let's imagine you want to buy an ice-cream for 10 of your friends. Write a program that will take the money you have and the price of one ice-cream, and will output the remaining money only if you can buy that ice-cream for your all 10 friends. Sample Input 80 7 Sample Output 10 Explanation To buy 10 ice-creams you need 7*10 = 70. The remaining money is 80-70 = 10.
4 Answers
+ 3
Caroline Eliasson Why are you printing in string. Output should be integer value.
+ 3
Caroline Eliasson
It should be
remaining = money - price * friends
if remaining >= 0 and money <= 100:
print(remaining)
Check this info also
"Do not output anything if the total price is above 100."
+ 2
You have the wrong condition for the if-statement.
It should be like:
if total <= 100:
print (str(money-total))
because the text of the problem says "Do not output anything if the total price is above 100."
+ 2
Thank you! :)