-3

I am brand new to Python and coding in general. I attempted to look up my question before asking... It's either I didn't look hard enough (I hope not) or didn't know what to search.

So, I am attempting to learn Python from YouTube (please don't yell at me) and I've been emulating the teacher's code and didn't understand one part of the if statement.

def helloWorld(myString):
    print(myString)
    myName = input("What is your name? ")
    myVar = input("Enter a number: ")
    if(myName == "Matthew" and myVar == 0):
        print("Matthew is great")
    elif(myName == "Bob"):
        print("Bob is ok")
    else:
        print("hello world")
helloWorld("Hello function world")
helloWorld("Hello 123 world")

When i run it in the terminal...

Hello function world What is your name? Matthew Enter a number: 0 hello world Hello 123 world What is your name? Matthew Enter a number: 1 hello world

My question is about the if(myName == "Matthew" and myVar == 0): statement. I made sure both parameters were met on the if statement. But, it's outputting hello world. Can someone explain to me why if I put parentheses around the 0 it'll render the if statement true and output Matthew is great? As soon as I take the parentheses off the 0, it'll render the if statement true``false. Hopefully, I was clear and concise about my question. Thank you in advance.

Uchi240
  • 1
  • 1

1 Answers1

0

Like TerryA said, replace

myVar = input("Enter a number: ")

with

myVar = int(input("Enter a number: "))

Alternately, replace

if(myName == "Matthew" and myVar == 0):

with

if(myName == "Matthew" and myVar == '0'):
Pete
  • 504
  • 4
  • 15