-1
x = True
y = False
i = input("How many nose you have : ")

ans = 1

if i == 1:
    print(x)
elif i == 2:
    print(y)
print(ans)

If I give an input of 2, it should print the value of y. However, it is not printing the value of y for this input. I'm not sure how to solve this issue.

BrokenBenchmark
  • 18,126
  • 7
  • 21
  • 33
David
  • 19
  • 3

3 Answers3

2

input() returns a string. You should use:

i = int(input("How many nose you have : "))

to cast the input to an integer.

BrokenBenchmark
  • 18,126
  • 7
  • 21
  • 33
0

the thing is input() from python takes everything in string, to use it in other datatype you have to typecast it or compare in string

x = True
y = False
i = input("How many nose you have : ")

ans = 1

if int(i)==1:
    print(x)
elif int(i)==2:
    print(y)
print(ans)
0
x = True
y = True
i = int(input("How many nose you have: "))

ans = 1

if i == 1:
    print(x)
elif i == 2:
    print(y)
print(ans)

Though I don't recommend doing it like this because you can still do 3 and other numbers. I'd recommend doing it like this instead:

a = int(input("How many nose do you have?: "))
ans = 1

if a == ans:
    print(True)
else:
    print(False)
print("The answer is " + ans + "!")