+ 1

Code fail

What is wrong with my code score=100 shots=4 while shots>0: result=input() if result=="hit" : score +=10 shots-=1 elif result=="miss" : score -=20 shots -=1 print(score)

20th Nov 2021, 10:54 AM
Iakovos Xalka
Iakovos Xalka - avatar
6 Answers
+ 5
You need to fix your indentation so everything inside the while loop but that last line is indented a whole block
20th Nov 2021, 10:57 AM
Slick
Slick - avatar
+ 3
John Delvin most likely wrong. Does OP want to print the score only when they miss?
20th Nov 2021, 11:27 AM
Slick
Slick - avatar
0
Slick , here is the correction score=100 shots=4 while shots>0: result=input() if result=="hit" : score +=10 shots-=1 elif result=="miss" : score -=20 shots -=1 print(score)
20th Nov 2021, 12:04 PM
John Delvin
John Delvin - avatar
0
John Delvin that assumes that they want to print the score after every shot. I don't think that's the case. So the print statement should probably be placed outside of the loop.
20th Nov 2021, 12:49 PM
Simon Sauter
Simon Sauter - avatar
0
Simon Sauter for me i love to see some out when i do something. In games when you kill or shoot someone , some progress is shown and it still appears for as long as the game runs.I thought that was what the owner of this post wanted
21st Nov 2021, 10:21 AM
John Delvin
John Delvin - avatar
- 6
This is the indented version score=100 shots=4 while shots>0: result=input() if result=="hit" : score +=10 shots-=1 elif result=="miss" : score -=20 shots -=1 print(score)
20th Nov 2021, 11:26 AM
John Delvin
John Delvin - avatar