+ 10

Skee-ball from Code Coach

Result is error for test 3. What wrong? https://code.sololearn.com/cJJj828SQ8rv/?ref=app

1st Jan 2020, 9:15 PM
Petr
39 Respostas
+ 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)
1st Jan 2020, 10:04 PM
Petr
+ 7
x=int(input()) y=int(input()) if ((x/12)>=y): print("Buy it!") else: print("Try again") I code that, and it solves
2nd Jan 2020, 12:42 PM
HoĆ  XuĆ¢n NĆ“ng
HoĆ  XuĆ¢n NĆ“ng - avatar
+ 5
a / 12 >= b is enough. You not need math.trunc()
1st Jan 2020, 9:47 PM
Denise RoƟberg
Denise RoƟberg - avatar
+ 4
Petr I am not sure but your code does not work for costs = 0.
1st Jan 2020, 10:05 PM
Denise RoƟberg
Denise RoƟberg - avatar
+ 4
Russ Denise RoƟberg I think problem is solve. Thank you.
1st Jan 2020, 10:08 PM
Petr
+ 4
Petr yes, it's possible Denise RoƟberg nailed it there - very good point.
1st Jan 2020, 10:10 PM
Russ
Russ - avatar
+ 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')
3rd Jan 2020, 1:56 AM
Paul K Sadler
Paul K Sadler - avatar
+ 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...
1st Jan 2020, 9:39 PM
Petr
+ 3
Russ Ok
1st Jan 2020, 9:42 PM
Petr
+ 3
Russ a=int(input()) b=int(input()) if a-12*b>0: print("Buy it!") else: print("Try again") Not work
1st Jan 2020, 9:47 PM
Petr
+ 3
Denise RoƟberg It is only one variant from many other. I mean trunc()...
1st Jan 2020, 9:49 PM
Petr
+ 3
Russ I used early variant b==0, and includid it in add if. But it is not change the result
1st Jan 2020, 9:51 PM
Petr
+ 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
1st Jan 2020, 9:55 PM
Petr
+ 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
3rd Jan 2020, 3:47 AM
HoĆ  XuĆ¢n NĆ“ng
HoĆ  XuĆ¢n NĆ“ng - avatar
+ 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.
1st Jan 2020, 9:32 PM
Russ
Russ - avatar
+ 2
Petr Like I said, try to do *without* dividing.
1st Jan 2020, 9:41 PM
Russ
Russ - avatar
+ 2
Petr Why does it need to be strictly greater than 0?
1st Jan 2020, 9:49 PM
Russ
Russ - avatar
+ 2
Petr And I mean if a / 12 >= b: //print else: //print works for all cases.
1st Jan 2020, 9:52 PM
Denise RoƟberg
Denise RoƟberg - avatar
+ 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.
1st Jan 2020, 10:01 PM
Russ
Russ - avatar
+ 2
Sorry - misread. Again, not sure, sorry.
1st Jan 2020, 10:07 PM
Russ
Russ - avatar