Problem in hovercraft (python) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Problem in hovercraft (python)

It still writes loss at 7 and at 10 don’t know y please help me fined the bug boat = int(input()) cost = 21000000 boat * 3000000 if boat < cost: print ('Loss') elif boat == cost: print ('Broke Even') elif boat > cost: print ('Profit')

27th Sep 2021, 8:20 PM
Lz1234
3 Answers
+ 3
The problem is in line 3. It should be boat = boat * 3000000
27th Sep 2021, 8:38 PM
Simon Sauter
Simon Sauter - avatar
+ 1
Simon Sauter Does python see it this way in the buged edition Does it see it as if there are 2 difreant boats one as in boat input And one as in boat * 3000000 If its wrong can you explaine what the computer sees it as
27th Sep 2021, 9:12 PM
Lz1234
+ 1
When you use boat = boat * 3000000 the value of boat is overwritten. Since you don't need the original value anymore that is no problem in this case. Alternatively you could create a new variable. E.g. income = boat * 3000000 In this case you have to use income instead of boat in the conditionals. The advantage is that if you do it like this you still have the original value stored in the boat variable. So whenever you might need the original value again you should create a new variable. If you just use boat * 3000000 the calculation is executed, but the result is not saved.
27th Sep 2021, 9:19 PM
Simon Sauter
Simon Sauter - avatar