0

Struggling with a python code challenge

I’m working on the “pull the trigger” challenge and I keep getting an EOF error and it looks like it’s my input line that is causing issues. However, when I load my code in the playground I get the expected output (along with the error). Anyone have any ideas as to why this would be an issue? score = 100 attempt = 1 while attempt <= 4: print("what was the result") result = input() if result == "hit": score += 10 print(score) elif result == "miss": score -= 20 print(score) attempt += 1

4th Sep 2021, 9:25 PM
John Corbin
7 RĂ©ponses
+ 1
Your code has two issues: 1. In the if block you need to add attempt += 1 2. If I remember correctly the task requires only the final score ad output. So the print statement should be outside the loop.
4th Sep 2021, 9:38 PM
Simon Sauter
Simon Sauter - avatar
+ 1
EOF error is because sololearn accepts all inputs in the first prompt (each input in a line) and then prints the output, Try run this code in another IDE, and I think it will work properly
4th Sep 2021, 9:32 PM
Sousou
Sousou - avatar
+ 1
Thanks for the help!!!
4th Sep 2021, 9:46 PM
John Corbin
0
Yeah if seems to work in the playground. Trying to figure out how to satisfy sololearn’s requirements so i can pass the challenge. But it’s good to know that it’s not flat out bad code 🙂
4th Sep 2021, 9:37 PM
John Corbin
0
Ah the final score. That makes sense. The examples they gave had the var += 1 statement at the very end so thsts what i did đŸ€·â€â™‚ïž
4th Sep 2021, 9:40 PM
John Corbin
0
You can do it with a single use of attempt += 1 if you unindent it so it is executed independently of whether the if or the elif block is executed.
4th Sep 2021, 9:42 PM
Simon Sauter
Simon Sauter - avatar
0
Nvm i see what you mean
4th Sep 2021, 9:44 PM
John Corbin