-1
while True:
  sales = input("Enter how much money the business made from sales: ")
  if input == int():
    break
  else:
    print("Sorry please enter a number")

When I run the code and I put an intger it says that it is not and tells me to retry. It should only happen if the input is a string not an intger.

Odiac
  • 1
  • 1
    `input` always returns `str`. You might want `if sales.isnumeric()`. Or force convert the input to int using `int(sales)` within a `try/except` block. – not_speshal May 10 '22 at 16:03
  • Your line `input == int()` is checking to see whether the built-in method `input` is equal to the built-in object type `int`. This is different from checking whether the variable you have created via input, `sales`, is an instance of the `int` type. See [What is the canonical way to check for type in python](https://stackoverflow.com/questions/152580/whats-the-canonical-way-to-check-for-type-in-python) and [How can I read inputs as numbers](https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-numbers) – G. Anderson May 10 '22 at 16:04
  • You can see what type an object is by using the `type()` method. For example, `type(sales)`. Try running the following after taking your input: `print(f'input is a {type(input).__name__}; int is a {type(int).__name__}; sales is a {type(sales).__name__}')` – G. Anderson May 10 '22 at 16:11
  • @G.Anderson actually, because of the parentheses, it is checking whether the method is equal to the integer zero. – Karl Knechtel May 10 '22 at 16:14
  • @KarlKnechtel ah, I missed that piece, thanks for pointing that out – G. Anderson May 10 '22 at 16:21

0 Answers0