+ 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 ?
43 Réponses
+ 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)
+ 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.
+ 4
I guess this is the question of Code Coach. If I'm right, then you should solve it yourself.
+ 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"
+ 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!
+ 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.
+ 3
Finally, it works. Thank you Zachary! I forget one condition that money may be smaller than total price. Then it will be meaningless.
+ 2
There is a colon missing at the end of the line with if...
if total_price <=100: # -<<<
+ 1
Перейдите в верхний чат и найдите мое имя в правом углу, и вы увидите мой код
+ 1
money = int(input())
price = int(input())
# место для вашего кода
allprice = price*10
if money >= allprice:
balance=money-allprice
print(balance)
+ 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?
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)
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)
0
Thank you Lothar! However, Test case #4 still doesn’t work. And the test case is hidden.
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.
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.
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
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 ()
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)
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