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
19 ответов
+ 5
Dalton Hoover Yes, as I said, your code won't work correctly if you keep asking for input inside a loop.
+ 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.
+ 5
Dalton Hoover You're very welcome 😁 mark me best answer pls 😉👍🏻
+ 4
Can you post the code?
+ 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.
+ 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
+ 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).
+ 3
Never took me long to save my codes. You can open the coding playground on your PC by accessing SoloLearn via web.
+ 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.
+ 1
yeah on my computer on solo learns play ground when it asks for input i do
+
2
2
is that right ?
+ 1
ok ty vm im gonna try again i greatly appreciate you taking the time to answer my questions
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)
0
the division was messed up during my copy ignore that bit
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
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 ?
0
does it usually take a while to save them ? im attempting to save it so i can show it to you
0
yeah that's what I was copying from yeah it is being slow idk why
0
so completely take it out ?
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