0

Pull the Trigger

Game where you output 'Hit' or 'Miss' with a total of 110 points My code: points = 100 action = 4 while action < 5: result = input() if result=="hit": points += 10 action -= 1 elif result == "miss": points -=20 action -=1 print (points)

6th Jul 2021, 1:00 AM
Kevin Calderon
Kevin Calderon - avatar
5 odpowiedzi
+ 2
Kevin Calderon You will get error because you are decrementing action after each iteration so loop will work till infinite because of condition action < 5. Since there is only 4 iteration so you have to initialise action with 1 and after each iteration you should increment counter instead of decrement.
6th Jul 2021, 1:33 AM
A͢J
A͢J - avatar
+ 1
1) your while condition is wrong, as you start action as 4 and decrease it by one at each iteration... however, to take 5 actions, rather initialize action to zero, and increase it by one at each iteration ^^ 2) your if/elif blocks seems indented, but that's not clear: rather use more spaces to male the indentation clearer 3) I guess the print(points) must occurs only after 5 actions done... so without any indentation 4) if the game should end at 110 points, you must test it inside while loop and break if >= 110
6th Jul 2021, 1:17 AM
visph
visph - avatar
+ 1
copy the full task description if you want to be helped further ;)
6th Jul 2021, 1:18 AM
visph
visph - avatar
+ 1
Your action will always be less than 5 because you are only decrementing it... See maybe you miss out some info in the question ❓
6th Jul 2021, 3:14 AM
Sumit Kumar
Sumit Kumar - avatar
+ 1
Thanks, everyone. There are still some issues I have. But, I at least got it to run now.
6th Jul 2021, 11:47 PM
Kevin Calderon
Kevin Calderon - avatar