0

I made a mistake in the code: I can not find where. help me please =)

Task - Ballpark Orders: https://www.sololearn.com/coach/15?ref=app My code: https://code.sololearn.com/cLW3M85EE8vf/?ref=app 2/5 of the tests are successful, the rest of the tests fail and they are hidden. Anyone have any ideas where I made a mistake?

12th May 2020, 6:29 PM
Ivan Sholokhov
Ivan Sholokhov - avatar
8 Respostas
+ 1
I think there may be a rounding error here. My advice: change tax = subtotal * 1.07 to tax = subtotal * 107/100. This should stop the rounding error.
12th May 2020, 8:24 PM
Russ
Russ - avatar
+ 2
You haven't included what to do if i is "NACHOS". You need an extra elif i == "NACHOS":
12th May 2020, 6:39 PM
Russ
Russ - avatar
+ 1
Yes, it worked! Thanks! Right now I was thinking about trying to round out the output, but using my curve method: ... total_with_tax = ("%6.2f" % (subtotal * 1.07)) ... And thank You for Your advice on rounding!
12th May 2020, 8:33 PM
Ivan Sholokhov
Ivan Sholokhov - avatar
+ 1
The common way is to use round(). print(round(subtotal*1.07, 2)) should work too I think. The 2 means to 2 decimal places in case you weren't sure.
12th May 2020, 9:19 PM
Russ
Russ - avatar
+ 1
To better remember, I also checked "round()" - this method also works. Thanks
12th May 2020, 9:40 PM
Ivan Sholokhov
Ivan Sholokhov - avatar
0
Russ, thank you! I added "elif i = = "nachos": ..." It should have worked, but it didn't... The same result is 2/3 It is logical that the problem is in the 'NACHOS', but what is it?...
12th May 2020, 8:17 PM
Ivan Sholokhov
Ivan Sholokhov - avatar
0
Did you try that too?
12th May 2020, 8:44 PM
Russ
Russ - avatar
0
Yes, both options work. But I think yours is more appropriate. I don't even know how this thing I wrote works, just copied it from the Internet. *Facepalm* Your option is simpler and works.
12th May 2020, 9:01 PM
Ivan Sholokhov
Ivan Sholokhov - avatar