0

WhatsApp am I dringend wromg? EOF errot

I got Problem wird this Code in my python course. The Code is similar to the solution: total = 0 i = 0 while i < 5: age = int(input()) if age < 3: continue i += 1 total += 100 print(total) I get an EOF error when reading line Its the line with: age = int(input())

6th Jan 2023, 5:54 PM
Julian Freund
Julian Freund - avatar
3 odpowiedzi
+ 2
i+=1 should executed independent of input value. You increment only when age < 3 false. So it ask atleast 5 inputs age<3 Increment it just after taking input.
6th Jan 2023, 6:07 PM
Jayakrishna 🇮🇳
+ 1
Use a try-except block: try: total = 0 i = 0 while i < 5: age = int(input()) if age < 3: continue i += 1 total += 100 print(total) except EOFError as e: print(e)
6th Jan 2023, 6:12 PM
Edgar Sabido
Edgar Sabido - avatar
0
it looks like you are using a while loop to read input from the user and the loop is not terminating because the user is not providing any input. To fix the EOF error, you need to make sure that the user is providing the necessary input. One way to do this is to prompt the user for input and let them know what is expected. For example: total = 0 i = 0 while i < 5: age = input("Please enter your age: ") try: age = int(age) except ValueError: print("Sorry, that was not a valid age. Please try again.") continue if age < 3: continue i += 1 total += 100 print(total)
6th Jan 2023, 6:41 PM
Aditya Dixit