+ 10
Skee-ball from Code Coach
Result is error for test 3. What wrong? https://code.sololearn.com/cJJj828SQ8rv/?ref=app
39 Réponses
+ 4
Russ
It is ok, but why
If a//(b*12)>0:
...
Don,t work?
My be you have a link of article about so type and examples? (length of types)
+ 7
x=int(input())
y=int(input())
if ((x/12)>=y):
print("Buy it!")
else:
print("Try again")
I code that, and it solves
+ 5
a / 12 >= b is enough. You not need math.trunc()
+ 4
Petr
I am not sure but your code does not work for costs = 0.
+ 4
Russ Denise Roßberg
I think problem is solve. Thank you.
+ 4
Petr yes, it's possible Denise Roßberg nailed it there - very good point.
+ 4
Petr here is an alternative
points = int(input())
cost = int(input())
import math
tickets = math.floor(points/12)
if tickets >= cost:
print('Buy it!')
else:
print('Try again')
+ 3
Russ
I try many variants,f.e.: a//12//b>0, round, other functions of math, but always result is false for test 3. I can not see task for this variant. I try to do this second day...
+ 3
Russ
Ok
+ 3
Russ
a=int(input())
b=int(input())
if a-12*b>0:
print("Buy it!")
else:
print("Try again")
Not work
+ 3
Denise Roßberg
It is only one variant from many other. I mean trunc()...
+ 3
Russ
I used early variant b==0, and includid it in add if. But it is not change the result
+ 3
Russ Denise Roßberg
Thank you . I get 5 ok. But i do not like it, couse i don,t understand why my early codes are not right
+ 3
Has some problems with round(float) in python. If you take round(0.5) it will return 0, round(2.5) return 2. But round(1.5) return 2
+ 2
Hmm, seems like it *should* work. Maybe it comes down to a rounding error. See if you can modify it to work without dividing.
+ 2
Petr Like I said, try to do *without* dividing.
+ 2
Petr Why does it need to be strictly greater than 0?
+ 2
Petr
And I mean
if a / 12 >= b:
//print
else:
//print
works for all cases.
+ 2
Ok so you have it now. What I was trying to get you to do was:
if a-12*b>=0:...
the ">=" was the sticking point that you'd missed.
I'm not sure why your original code failed, as I said earlier. I can only assume that case had the *exact* number of points necessary to get the prize, and somehow a rounding error wheb dividing worked its way in. I couldn't find an example to demonstrate it though.
(a/12)//b>0 would fail, whereas (a/12)>=b would work.
+ 2
Sorry - misread. Again, not sure, sorry.