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!")
Asked
Active
Viewed 43 times
0
-
Can you provide your input? Also, why are you using `is`? You should use `==` – astrochun Jul 07 '22 at 16:20
-
whether you use 'is' or '==' its the same thing because both serve as conditional expressions. I tried with '==' first, but it didn't work so I changed it to 'is', but even then it is not working. You can try running the code yourself, and see if it works – saptarshi Jul 07 '22 at 16:23
-
Well your code isn't properly formatted according to PEP8 so it doesn't make it easy to use – astrochun Jul 07 '22 at 16:32
-
You are returning greet before getting to the if statements – Sam Jul 07 '22 at 16:34
-
@saptarshi, no, `is` and `==` are definitely _not_ the same in Python. See https://stackoverflow.com/q/132988/354577 – ChrisGPT was on strike Jul 07 '22 at 22:04
-
1Why are you using conditionals in the first place? The body is the same for both of them. – ChrisGPT was on strike Jul 07 '22 at 22:04
1 Answers
1
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

Kiran Parajuli
- 820
- 6
- 14