0

Eof error when reading a line

trying to make a calculator user_input = input (: ) i dont understand what's wrong my calculator options print but the function wont happen

18th Aug 2018, 3:59 PM
Dalton Hoover
Dalton Hoover - avatar
19 odpowiedzi
+ 5
Dalton Hoover Yes, as I said, your code won't work correctly if you keep asking for input inside a loop.
18th Aug 2018, 4:45 PM
Eduardo Petry
Eduardo Petry - avatar
+ 5
Dalton Hoover Yes, that should work, but I do believe the while loop can be causing trouble. You cannot ask for new input during runtime here.
18th Aug 2018, 4:27 PM
Eduardo Petry
Eduardo Petry - avatar
+ 5
Dalton Hoover You're very welcome 😁 mark me best answer pls 😉👍🏻
18th Aug 2018, 4:48 PM
Eduardo Petry
Eduardo Petry - avatar
+ 4
Can you post the code?
18th Aug 2018, 4:08 PM
Eduardo Petry
Eduardo Petry - avatar
+ 4
Where are you trying to run this code? Here in SoloLearn's coding playground you must provide your input in separate lines before execution of the program (that can be your issue). Also, I think while loops do not work here because you cannot keep on asking for new input during runtime. Another issue I see here: when the operator is "/" you need to make sure that 'num2' is not 0, or you'll end up with a ZeroDivisionError.
18th Aug 2018, 4:23 PM
Eduardo Petry
Eduardo Petry - avatar
+ 4
Also, I suggest you save this code in your profile so you can insert it instead of copying and pasting here. Like this (one of my codes for example): https://code.sololearn.com/c2G7Otp6LMAy/?ref=app
18th Aug 2018, 4:29 PM
Eduardo Petry
Eduardo Petry - avatar
+ 4
You should remove the while loop for it to work in SoloLearn. You should get input only once (before execution), or else it does not compile (i think).
18th Aug 2018, 4:30 PM
Eduardo Petry
Eduardo Petry - avatar
+ 3
Never took me long to save my codes. You can open the coding playground on your PC by accessing SoloLearn via web.
18th Aug 2018, 4:34 PM
Eduardo Petry
Eduardo Petry - avatar
+ 2
Dalton Hoover your code is fine and works fine the problem is the way sololearn runs the code on there servers you have to input all your inputs in the begining. on a normal ide you would be able to keep inputing as it asks you and it would wait but here if you input + 5 6 it will print all all the lines and add 5 and 6 for you and then give you an error because there is no more inputs for it. if you put in the first box + 5 6 quit it will print everything like before then then use your quit option and you will see no error.
18th Aug 2018, 5:32 PM
Mooaholic
Mooaholic - avatar
+ 1
yeah on my computer on solo learns play ground when it asks for input i do + 2 2 is that right ?
18th Aug 2018, 4:25 PM
Dalton Hoover
Dalton Hoover - avatar
+ 1
ok ty vm im gonna try again i greatly appreciate you taking the time to answer my questions
18th Aug 2018, 4:47 PM
Dalton Hoover
Dalton Hoover - avatar
0
while True: print("Options") print("Enter '+' to add two numbers") print("Enter '-' to subtract two numbers") print("Enter '*' to multiply two numbers") print("Enter '/' to multiply two numbers") print("Enter 'quit' to end the program") user_input = input(": ") if user_input == "quit": break elif user_input == "+": num1 = float(input("Enter a number:")) num2 = float(input("Enter another number:")) result = str(num1 + num2) print("The answer is" + result) elif user_input == "-": num1 = float(input("Enter a number: ")) num2 = float(input("Enter another number")) result = str(num1 - num2) print("The answer is" + result) elif user_input == "*": num1 = float(input("Enter a number:")) num2 = float(input("Enter another number: ")) result = str (num1 * num2) print("The answer is" + result) elif user_input== "/": a number:")) num1 = float(input("Enter a number:")) num2 = float(input("Enter another number: ")) result = str(num1 / num2) print("The answer is" + result)
18th Aug 2018, 4:08 PM
Dalton Hoover
Dalton Hoover - avatar
0
the division was messed up during my copy ignore that bit
18th Aug 2018, 4:17 PM
Dalton Hoover
Dalton Hoover - avatar
0
Options Enter '+' to add two numbers Enter '-' to subtract two numbers Enter '*' to multiply two numbers Enter '/' to multiply two numbers Enter 'quit' to end the program : Enter a number:Enter another number:The answer is24.0 Options Enter '+' to add two numbers Enter '-' to subtract two numbers Enter '*' to multiply two numbers Enter '/' to multiply two numbers Enter 'quit' to end the program : Traceback (most recent call last): File "..\Playground\", line 8, in <module> user_input = input(": ") EOFError: EOF when reading a line this is my output sorry this is my first attempt at anything
18th Aug 2018, 4:20 PM
Dalton Hoover
Dalton Hoover - avatar
0
yeah its repeating the options and it is technically answering the problem i just dont know what the issue is i guess. should i replace the while loop with something ?
18th Aug 2018, 4:29 PM
Dalton Hoover
Dalton Hoover - avatar
0
does it usually take a while to save them ? im attempting to save it so i can show it to you
18th Aug 2018, 4:33 PM
Dalton Hoover
Dalton Hoover - avatar
0
yeah that's what I was copying from yeah it is being slow idk why
18th Aug 2018, 4:35 PM
Dalton Hoover
Dalton Hoover - avatar
0
so completely take it out ?
18th Aug 2018, 4:41 PM
Dalton Hoover
Dalton Hoover - avatar
0
ok ty but could you elaborate just a bit on what you mean by putting all my inputs in the beginning an example if you would
18th Aug 2018, 6:06 PM
Dalton Hoover
Dalton Hoover - avatar