+ 1

[Solved] Learning Python IF statement V training problem

I've written the code, but it doesn't pass the 4th secret test, I don't understand, what's the problem. Code: money = int(input()) price = int(input()) costs = price * 10 if ( (costs <= 100) and ( costs <= money) and (money > 0) and (price > 0) ): print (money - costs) I saw that 4 test checks the output in case of negative result, but I have a condition (costs <= money). Any idea, what's wrong? ------ UPD. Solution: money = int(input()) price = int(input()) total = price * 10 if money >= 0 and price >=0: remaind = money - total if remaind <= 100 and remaind >= 0: print (remaind)

4th Nov 2020, 1:08 PM
Георгий Ерёмин
Георгий Ерёмин - avatar
22 Answers
+ 16
Their might be some bugs in the written statement which is causing error. Take an look here The line “Don’t print anything if money > 100” should be like “Don’t print anything if the remainder is > 100”. As at current statement the 4th test case is failing continuously do either the test case contain bug or the statement so for now this assumption is much more validate. money = int(input()) price = int(input()) total = price*10 #your code goes here if money >=0 and price>=0: remaind = money - total if remaind<=100 and remaind>=0: print (remaind) Than the problem should be fixed. https://www.sololearn.com/discuss/2575215/?ref=app
4th Nov 2020, 3:21 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 3
It‘s not a bug. Try this... money = int(input()) price = int(input()) total = price*10 You want to output the remaining money IF: 1. total is NOT bigger than money OR 2. total is NOT bigger than 100 Write this out as one if statement and you‘re good to go.
4th Nov 2020, 3:04 PM
_cm_
+ 3
Георгий Ерёмин In your very first variant: Delete all the parentheses in the if statement, change and to or and delete the second equal sign.
4th Nov 2020, 3:29 PM
_cm_
+ 2
Would have been great if you had posted the code coach
4th Nov 2020, 1:13 PM
Steve Sajeev
Steve Sajeev - avatar
+ 1
GAWEN STEASY, you were right, there might be "Don't print anything if remainder > 100" Thanks a lot! The working code is: money = int(input()) price = int(input()) total = price * 10 if money >= 0 and price >=0: remaind = money - total if remaind <= 100 and remaind >= 0: print (remaind)
4th Nov 2020, 3:57 PM
Георгий Ерёмин
Георгий Ерёмин - avatar
0
The task: 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. Do not output anything if the total price is above 100.
4th Nov 2020, 1:23 PM
Георгий Ерёмин
Георгий Ерёмин - avatar
0
>Try this https://code.sololearn.com/cbNWT7Q0wD1R/?ref=app The same result, secret test #4 is failed
4th Nov 2020, 2:03 PM
Георгий Ерёмин
Георгий Ерёмин - avatar
0
If money < cost then I think it fails. Need no output.. Edit : For your original code, try including conditions for money=0,price=0. Further error means I guess a bug. Others facing same.
4th Nov 2020, 2:13 PM
Jayakrishna 🇮🇳
0
>If money < cost then I think it fails. Need no output.. Yes, that's why i check this condition ( costs <= money) in my start version.
4th Nov 2020, 2:21 PM
Георгий Ерёмин
Георгий Ерёмин - avatar
0
>Check it again Simba, the 4th test is failed again
4th Nov 2020, 2:27 PM
Георгий Ерёмин
Георгий Ерёмин - avatar
0
>For your original code, try including conditions for money=0,price=0. Jayakrishna🇮🇳, I tried conditions money and price >= 0 . Ok, I'll consider this as a bug. Thanks!
4th Nov 2020, 2:33 PM
Георгий Ерёмин
Георгий Ерёмин - avatar
0
Георгий Ерёмин am not sure about that. But on reading it again that I guessing if price is over than money then you cant buy any. But in this case it's not said not to print any so remaining is same money may needed to print. A wild guess upon checking all condition.
4th Nov 2020, 2:50 PM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳, I understand the phrase in task "... will output the remaining money only if you can buy that..." so that I shouldn't print the remaining money if (costs > meney)
4th Nov 2020, 3:01 PM
Георгий Ерёмин
Георгий Ерёмин - avatar
0
Oh. I miss read it. Not seen 'only if'.. Ok then may be bug..
4th Nov 2020, 3:05 PM
Jayakrishna 🇮🇳
0
_cm_, that was my very first variant, it doesn't work because of test #4 money = int(input()) price = int(input()) total = price * 10 if ( (total <= 100) and (total <= money) ): print (money - total)
4th Nov 2020, 3:12 PM
Георгий Ерёмин
Георгий Ерёмин - avatar
0
This works. The last one.
30th Nov 2020, 5:05 PM
Amit Kumar
Amit Kumar - avatar
0
Thanks... this worked and i finally get why! money = int(input()) price = int(input()) total = price * 10 if money >= 0 and price >=0: remaind = money - total if remaind <= 100 and remaind >= 0: print (remaind)
18th May 2021, 4:20 AM
Frank
0
guys no im on a different question for quiz 4 its about:Fill in the blanks to take a number from input and output "Pass", if it s greater than 70. grade = (input()) grade > :("Pass")/ and its broken for me🤣🤣🤣 silly website😭🤭🤗😉🥳🤩😌😏😍🥰😊☺️😘😚🥲🙂😙😗🙃😀😃😄😁
25th Jul 2021, 5:19 AM
Mason Starbuck
Mason Starbuck - avatar
0
hahahahahahahahahha
28th Jul 2022, 5:58 AM
IMAN NAJIA SUHAILI
IMAN NAJIA SUHAILI - avatar
0
grade = int(input()) if grade > 70: print("Pass")
9th Oct 2022, 8:19 PM
Abdoulrazak Omar Bogoreh
Abdoulrazak Omar Bogoreh - avatar