+ 1

If-statements Problem

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 7*10 = 70. 10 is remaining money (80-70). _________________________________________________ Does anyone know how to solve it via Python ?

7th Sep 2020, 12:06 PM
Jade Gao
Jade Gao - avatar
43 Antworten
+ 9
I got it. You still cannot see test case #4 but it must be the only one with a remaining value to output. Try the code below. total = price * 10 remainder = money - total if remainder >= 0: print(remainder)
10th Sep 2020, 3:30 AM
Zachary Osborne
Zachary Osborne - avatar
+ 8
Krishn Priya Singh , it is better for you to start your own post, otherwise poeple will not get aware of you. please also include your current code in the post.
24th Jan 2023, 6:40 PM
Lothar
Lothar - avatar
+ 4
I guess this is the question of Code Coach. If I'm right, then you should solve it yourself.
7th Sep 2020, 12:09 PM
Charitra
Charitra - avatar
+ 4
You are using a variable name called "remaining money". spaces are not allowed in identifier names. use "remaining_money" instead. The same is with variable name "total price"
7th Sep 2020, 2:51 PM
Lothar
Lothar - avatar
+ 4
Jade Gao , i suppose that your description is not the complete story. Is it possible to get the COMPLETE task description? Sometimes it's just a tiny detail that makes the difference. Please also give an information from where this challenge is coming. Solo, HR, LC, ...Thanks!
9th Sep 2020, 4:01 PM
Lothar
Lothar - avatar
+ 4
Yinka Bello , please do not start a new thread inside an existing thread of an other person. You have just started the python tutorial, so please continue learning and practicing. some new things may look a bit confusing at the first view, but this will change.
5th Jan 2021, 1:01 PM
Lothar
Lothar - avatar
+ 3
Finally, it works. Thank you Zachary! I forget one condition that money may be smaller than total price. Then it will be meaningless.
10th Sep 2020, 12:39 PM
Jade Gao
Jade Gao - avatar
+ 2
There is a colon missing at the end of the line with if... if total_price <=100: # -<<<
8th Sep 2020, 3:35 PM
Lothar
Lothar - avatar
+ 1
Перейдите в верхний чат и найдите мое имя в правом углу, и вы увидите мой код
25th Nov 2020, 1:41 PM
Sagar Rana
Sagar Rana - avatar
+ 1
money = int(input()) price = int(input()) # место для вашего кода allprice = price*10 if money >= allprice: balance=money-allprice print(balance)
10th Jul 2021, 9:02 AM
Konstantin
Konstantin - avatar
+ 1
write a program that checks if the water is boiling take the integer temperature in celsius as input and output boiling if the temperature is above or equal to 100. sample input 105 Sample output Boiling Does anyone know how to solve it python?
23rd Jan 2023, 3:39 PM
Krishn Priya Singh
Krishn Priya Singh - avatar
0
I tried as below but line 3 is an invalid syntax. Why? money = int(input()) price = int(input()) total price =10*price remaining money=money-total price if total price<=100 print (remaining money)
7th Sep 2020, 12:38 PM
Jade Gao
Jade Gao - avatar
0
I correct it as below but this time line 5 turns to be an invalid syntax. I’m confused. money = int(input()) price = int(input()) total_price =10*price remaining_money=money-total_price if total_price <=100 print (remaining_money)
8th Sep 2020, 12:36 PM
Jade Gao
Jade Gao - avatar
0
Thank you Lothar! However, Test case #4 still doesn’t work. And the test case is hidden.
9th Sep 2020, 2:05 PM
Jade Gao
Jade Gao - avatar
0
I get all the test cases to work but #4 also and they are hidden so I dont know what variables have an issue.
10th Sep 2020, 3:19 AM
Zachary Osborne
Zachary Osborne - avatar
0
Yeah the wording on the question is tricky. I had trouble with it for sure but if I could see the input and expected output for the 4th test case we could have figured out our error.
10th Sep 2020, 2:07 PM
Zachary Osborne
Zachary Osborne - avatar
0
pock=int(input('Enter an amount you have:')) price=int(input('Enter a price of an icecream:')) allprice=price*10 if pock>allprice: bal=pock-allprice print('Remaining amount is',bal) else: print("You cannot buy an icecram for 10 of your friends") I think it gives the same output
14th Sep 2020, 11:16 AM
ravi barnawal
ravi barnawal - avatar
0
I got the soluion for this problem, it will solve all five tasks. code: money = int(input()) price = int(input()) cal = price * 10 if money >= cal: leftOver = money - cal if leftOver >= 0: print (leftOver) else: print ()
16th Oct 2020, 2:19 PM
Sagar Rana
Sagar Rana - avatar
0
The former solution works, but is actually not in line with the problem statement. It explicitely asks to not print anything if the total price is above 100. This is not checked in the former. I used the code below, and like for so many others it didn't work for case #4 ... money = int(input()) price = int(input()) #your code goes here total = 10*price if(0 <= total <= 100): if (money >= total): print(money - total)
17th Oct 2020, 7:24 AM
CMW
0
Removing the check for the total to be below 100 to avoid writing anything in that case - as requested in the problem description - makes it work in all cases: total = 10*price if (money >= total): print(money - total) else: print() That is kind of ridiculous. Entering as money = 140 and as price = 12 gives an output of 20, which should not be case, as nothing should be printed if price is above 100. I am questioning the seriousness of this site and reconsider my pro membership
17th Oct 2020, 7:30 AM
CMW