+ 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.

1st Jan 2021, 9:55 AM
Caroline Eliasson
Caroline Eliasson - avatar
4 Answers
+ 3
Caroline Eliasson Why are you printing in string. Output should be integer value.
1st Jan 2021, 10:19 AM
A͢J
A͢J - avatar
+ 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."
1st Jan 2021, 10:29 AM
A͢J
A͢J - avatar
+ 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."
1st Jan 2021, 10:19 AM
Martin Ed
Martin Ed - avatar
+ 2
Thank you! :)
1st Jan 2021, 10:39 AM
Caroline Eliasson
Caroline Eliasson - avatar