0

Where is the bug?

I did this Skee-ball challenge and all but one of the test case was wrong, why is that? Where is my mistake? Here's my code: score = int(input()) price = int(input()) yourTicket = score // 12 if yourTicket // price != 0: print("Buy it!") else : print("Try again")

12th Jan 2021, 3:30 PM
WelfredK
WelfredK - avatar
4 odpowiedzi
+ 7
You're right about // can produce 0 (a//b whenever a<b) What about this way? points, cost = int(input), int(input) tickets = points // 12 print("Try again" if tickets < cost else "Buy it!")
13th Jan 2021, 4:11 AM
David Ashton
David Ashton - avatar
+ 2
Let's say yourTicket = 10 price = 10 10/10 = 1 # ! = 0 check 1 / 10 = 0.1 # also check but it shouldn't If you cut a cake in x pieces the result is never 0 So your if never fails
12th Jan 2021, 4:22 PM
Stefanoo
Stefanoo - avatar
+ 1
David Ashton Thanks, it's work!
13th Jan 2021, 4:38 AM
WelfredK
WelfredK - avatar
0
Well, I'm using "//" operator, so it won't print out 0.1
13th Jan 2021, 1:18 AM
WelfredK
WelfredK - avatar