Home > Back-end >  How to evaluate user's input in s loop?
How to evaluate user's input in s loop?

Time:10-08

I'm new in coding or programming so I hope for respect.

I want to evaluate all the user's input in a loop. But the user's input is like this "-9"

Like

Number = input("Enter operator and number like "-9"")
Operator = (" ","-","/")
while Number == (Operator   Number):
if Number == "-0":
    Total = 0
    Total  = Number 
    print(f"the result of {Number} is {total} ")
else:
    print("Invalid input")

If the user input is not like "-7" it will display "Invalid input". And if the user input "-0" it will compute all the numbers the user have inputted.

But it doesn't work huhuhu

CodePudding user response:

You can use double quotes for the text and single quotes for the number, so they don't close each other. You can get input forever using following code:

while True:
   Number = input("Enter operator and number like '-9'")
   # Place your next code here.

CodePudding user response:

In the input statement, you're closing the "Enter operator and number like" msg. This is creating more problems after that line, where all green parts are considered as string now. Also, in while statement, "w" should be small letter, python is case sensitive. Try doing this:

Number = input("Enter operator and number like '-9' ")
Operator = (" ","-","/")
while Number == (Operator   Number):
if Number == "-0":
    Total = 0
    Total  = Number 
    print(f"the result of {num} is {total} ")
  • Related