+ 3

Hi, does anyone could help me with the ice cream task

In the description of the task, said that I have to pretend that i want to buy ten ice creams for my ten friends, so I need to make a program that take my money and the price as an entrance and the exit has to be the remaining money only if a can pay for the ice creams. I don t have to make an exit if I don't have "enough money" for buy the ice creams. My problem is that the task have predetermined results , and for that reason I can't put my own price or my own amount of money. I can see the results and one of them is this The example: 100 money 10 price And the expected exit 0 With that example I actually can work this is the program : money =int(input()) price =int(input()) if money >= price : if price *10==100: if money - 100 == 0: print("0") And it actually works but only for that example In specific. But for the rest of the examples i don't know what to do. The others examples work with the program before but as individual no in the same program and that's the problem.

5th Feb 2021, 2:46 AM
Alan Restrepo
Alan Restrepo - avatar
13 Réponses
+ 7
anthony silver res = money - price * 10 if res >= 0: print(res) will give right output.
5th Feb 2021, 3:28 AM
A͢J
A͢J - avatar
+ 3
Cyan There is no limitation now. Every time task is changing. When I first time solved there was no limitation, second time when I checked there was limitation now again my code didn't work when I removed condition then it worked. I don't know why this is happening. anthony silver Just do this res = money - price * 10 if res >= 0: print(res)
5th Feb 2021, 3:25 AM
A͢J
A͢J - avatar
+ 1
As far as I remember there is a limitation to prices. I think 100? Based on the problem: "... only if I can pay for the ice cream" if price >= 100: print(0) else: print(price - (money*10))
5th Feb 2021, 2:53 AM
noteve
noteve - avatar
+ 1
Yes in deed, but my problem that I m having is with how make the money and the price match with the expected examples, i mean the process is with this task
5th Feb 2021, 3:06 AM
Alan Restrepo
Alan Restrepo - avatar
+ 1
anthony silver The problem is aking for the remaining money or the "change" after buying 10 ice cream. For example: 80 <--- money 7 <--- price each money = int(input()) price = int(input()) price = price*10 # get the total price for 10 friends # Then get the change by subtracting the money by price if money >= 100: print(0) else: print(money - price)
5th Feb 2021, 3:23 AM
noteve
noteve - avatar
+ 1
Ok
5th Feb 2021, 3:25 AM
Alan Restrepo
Alan Restrepo - avatar
+ 1
Let's imagine you want to buy an ice cream for 10 of your friends. Write a program that takes the money you have and the price of an ice cream, and that takes out the remaining money only if you can buy that ice cream for your 10 friends. Input example 80 7 Output example 10 Explanation 7 * 10 = 70. 10 is the remaining money (80-70).
5th Feb 2021, 3:27 AM
Alan Restrepo
Alan Restrepo - avatar
+ 1
I Am AJ ! I did not know that the challenge have changed. Thanks!
5th Feb 2021, 3:31 AM
noteve
noteve - avatar
+ 1
anthony silver Check note given in task. You have to print remaining money when it is greater than or equal to 0 otherwise don't print anything.
5th Feb 2021, 3:33 AM
A͢J
A͢J - avatar
+ 1
I try this other way money =int(input()) price =int(input()) if money >= price : if price *10==100: if money - 100 == 0: print("0") elif money >= price : if price * 10 == 130: if money - 130 == 21: print ("21") But it gives me (no output) That's the problem because i have to make the program for all the options not for only one of them
5th Feb 2021, 3:48 AM
Alan Restrepo
Alan Restrepo - avatar
+ 1
The only number in your code should be 10 for the 10 friends. Everything else you have to compute from input
5th Feb 2021, 9:05 AM
Benjamin Jürgens
Benjamin Jürgens - avatar
+ 1
anthony silver the problem with your approach is that you try to write code according to test cases. What will you do if there are 1000 test cases? Write your code only according to the problem description. "The exit has to be the remaining money only if a can pay for the ice creams" Or rephrased: "if I can pay for the ice cream, output the remaining money" Try to express that in two lines of code, 1 for condition, 2 for output For the first line: You have to pay 10 * price, so money has to be at least that or more
5th Feb 2021, 7:25 PM
Benjamin Jürgens
Benjamin Jürgens - avatar
0
Ok but how can I make that output match with the other outputs?
5th Feb 2021, 4:53 PM
Alan Restrepo
Alan Restrepo - avatar