0

I tried it with if not in and if != but both just won't work. I want it to print Error(...) if the input is not a number but now it always prints the error. Below is my code:

from time import sleep

symbol = input("Do you want to calculate with +, -, * or /? Answer: ")

if symbol not in {"+", "-", "*", "/"}:
    print("Error 400. Bad Request.")
    sleep(2)
    exit()


number1 = input("What " + symbol + " what do you want to calculate? (Only one Number) Answer: ")

if number1 != int:
    print("Error 400. Bad Request.")
    sleep(2)
    exit()

number2 = input("What " + symbol + " what do you want to calculate? (Only one Number) Answer: ")

if number2 != int:
    print("Error 400. Bad Request.")
    sleep(2)
    exit()

if symbol in {"+", "-", "*", "/"}:
    print(number1 + symbol + number2)
rigs
  • 1
  • You mean something like `number1 = int(input(...))`? `input()` itself will never return an integer in Python 3, only a string. – Fred Larson Aug 05 '21 at 15:39
  • You can use `type()` or `isinstance()` fr type checking. What you've done is checking whether the user input is the built in `int` class, not an instance of `int` – G. Anderson Aug 05 '21 at 15:39
  • Yes, the Input should only be numerical. – rigs Aug 05 '21 at 15:39
  • Also relevant: [How can I take inputs as numbers?](https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-numbers) – G. Anderson Aug 05 '21 at 15:40
  • Your input *isn't* a number. Ever. Even if it looks like one. Your input is a string. That's what `input` gives you. – Karl Knechtel Aug 05 '21 at 15:41

0 Answers0