-1

When I type in John and 0 the "John is great" statement is not executed. I don't understand why.
I know that the question might be really simple but I checked the code in Java and it was working correctly.

print("Hello world")
myName = input("What is your name?\n")
myVar = input("Enter a number: ") 

if(myName == "John" and myVar == 0):
    print("John is great")
elif(myName == "Bob"):
    print("You are ok")
else:
    print("Hello world")

2 Answers2

3

myVar is str type. Not int type.
You should fix myVar = int(input("Enter a number: "))

luthierBG
  • 164
  • 1
  • 9
0

0 and "0" are two different values. 0 == 0 is true; 0 == "0" is false.

input always returns a str, so entering 0 sets myVar to "0", not 0.

if myName == "John" and myVar == "0":
chepner
  • 497,756
  • 71
  • 530
  • 681