-3

I'm putting together a small program for a friend that requires an input from the user, and depending on the input it does a certain function

Heres my code:

 value = input ("Enter Number")

if value == 1:
      print("You entered 1")
elif value == 2 :
      print("You ented 2!")
else:
      print("hmmm")

However, even entering 1 or 2, it always prints "hmmm".

I've tried everything including making a new function and passing the input into it and still it doesn't take. Any advice?

  • Any advice - read the docs for [`input()`](https://docs.python.org/3/library/functions.html#input) especially about the return type. – buran Oct 06 '21 at 06:06

1 Answers1

0

That's because you are taking input as a string not an integer. Because of it your value is string and when it is compared with integer 1 or 2 it's coming false and the else condition gets satisfied.

Correct code:

value = int(input ("Enter Number"))

if value == 1:
      print("You entered 1")
elif value == 2 :
      print("You ented 2!")
else:
      print("hmmm")
senarijit1618
  • 389
  • 4
  • 16