+ 6

Why the first code cannot solve the code coach skee-ball?

Here is the code coach: https://www.sololearn.com/coach/21?ref=app I was solving the code coach skee-ball. I tried to solve the code coach with this code: https://code.sololearn.com/c64hfcKDg3ar/?ref=app but it's not solving the third test. Then I edited a little .Instead of this condition: ticket/gun>=1 I used this: ticket>=gun https://code.sololearn.com/cV5r9jy627V7/?ref=app and it works fine. I couldn't figure out what's the problem in the first code . From my thinking, the two code should give the same result.So why the third test failed in the first code?

4th Jan 2021, 4:05 PM
The future is now thanks to science
The future is now thanks to science - avatar
3 ответов
+ 5
After much black box testing, at last I deduced that Test Case #3 sets the price of the squirt gun to zero. That causes division by zero in your conditional. Proof: change the conditional to check for zero. if(gun==0 || ticket/gun>=1) Now it passes the test!
4th Jan 2021, 6:47 PM
Brian
Brian - avatar
+ 6
Thank you very much Volodymyr Chelnokov and Brian for cleaning my doubts .Before writing the second code, I wrote the line x=ticket/gun but didn't used the value of x in the condition ,yet the test case fails. Now I figured out only declaring the line x= ticket/gun or writing the condition if(ticket/gun>=1) will cause timeout error if the gun=0. Thanks to you two.
5th Jan 2021, 6:11 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 5
Maybe gun is 0 in the third test?
4th Jan 2021, 5:02 PM
Volodymyr Chelnokov
Volodymyr Chelnokov - avatar