简体   繁体   中英

If, elif, and else conditions are not working correctly in my code

def greeting(string):
    greet=["Good Morning"+' '+string]
    return(greet)

print("Enter your name")
name=input()

if(name is "Saptarshi"):
    greet=greeting(name)
    print(greet)

elif(name is "Gurpreet"):
    greet=greeting(name)
    print(greet)

else:
    print("No greeting for you!")

Use == instead of is.

Python is operator compares two variables and returns True if they reference the same object. If the two variables reference different objects, the is operator returns False.

a = 100
b = a
result = a is b # True

d = 10
e = 10
result = d is e # False

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM