Can you get user input within a while loop? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can you get user input within a while loop?

I'm fairly new to Python and was working on a practice assignment which needs 4 different user inputs to calculate a score. However, when it tries to take the input, I get an EOF error and it stops the code from executing. Can someone point me in the right direction? Here is my code: points = 100 i = 0 while i <= 4: target = input() i = i + 1 if target == "hit": points = points + 10 elif target == "miss": points = points - 20 else: print("error") print(points)

13th Jan 2022, 5:42 PM
Nathan Vedros
1 Answer
+ 2
if you know how many inputs i'd suggest a for loop. While loops are for when you dont know. Also to put multiple input in sololearn you need to enter all input at once, different inputs seperated by a new line
13th Jan 2022, 6:21 PM
Slick
Slick - avatar