0

Control Structures Simple Calculator EOF Error

I'm new so following directions. The comments section is full of alternative options for building the calculator. This is great but I'm not ready for that yet. I continue to get an EOF error for line 13 or 18 or 23 or 28. I have copied and pasted the exact code from the lesson. This leads me to believe the code in the lesson is written incorrectly. The input for the first number doesn't give me an option to input the number. This is the error: Traceback (most recent call last): File "./Playground/file0.py", line 18, in <module> num1 = float(input("Enter a number: ")) EOFError: EOF when reading a line This is the code from the lesson: while True: print("Options:") print("Enter 'add' to add two numbers") print("Enter 'subtract' to subtract two numbers") print("Enter 'multiply' to multiply two numbers") print("Enter 'divide' to divide two numbers") print("Enter 'quit' to end the program") user_input = input(": ") if user_input == "quit": break elif user_input == "add": num1 = float(input("Enter a number: ")) num2 = float(input("Enter another number: ")) result = str(num1 + num2) print("The answer is " + result) elif user_input == "subtract": num1 = float(input("Enter a number: ")) num2 = float(input("Enter another number: ")) result = str(num1 - num2) print("The answer is " + result) elif user_input == "multiply": num1 = float(input("Enter a number: ")) num2 = float(input("Enter another number: ")) result = str(num1 * num2) print("The answer is " + result) elif user_input == "divide": num1 = float(input("Enter a number: ")) num2 = float(input("Enter another number: ")) result = str(num1 / num2) print("The answer is " + result) else: print("Unknown input")

26th Feb 2020, 5:04 PM
James Burier
James Burier - avatar
3 Answers
+ 2
I see your confusion. I checked the lesson and it's not signaled that the code doesen't properly run on SL because of the way input is handled(check linked code). The code works fine on an IDE. (like Pydroid for Android devices) https://code.sololearn.com/WhiNb9BkJUVC/?ref=app
26th Feb 2020, 5:13 PM
Mihai Apostol
Mihai Apostol - avatar
+ 1
PC as in Sololern Web version or as your IDE? Edit: for SL Remove the while true line. Reindent everything and when you run the code, input all inputs before and then press submit(as in the tutorial I linked) Edit. For PC (not on SL) Install an IDE of your choice and run the code as it is. You will have the interactivity is designed for.
26th Feb 2020, 5:27 PM
Mihai Apostol
Mihai Apostol - avatar
0
so the code wasn't written to run on the pc? What should I do to fix it so I can run it via solo learn?
26th Feb 2020, 5:24 PM
James Burier
James Burier - avatar