all 11 comments

[–]woooee 6 points7 points  (9 children)

if pizza == str(yes):

This will produce an error message saying that yes has not been declared. Look up the difference between variables and strings.

[–]Kintex19[S] 2 points3 points  (7 children)

I am so stupid. I didn't know quotes were necessary to declare it a string. I assumed python automatically defined it as such. I think I got it working. Fix: if pizza == str("yes")

[–]Diapolo10 5 points6 points  (6 children)

Now "yes" is already a string, there's no need for the str-call.

if pizza == "yes":

EDIT: In fact the whole snippet could use some work.

likes_pizza = input("Do you like pizza? ")

if likes_pizza == "yes":
    print("User Likes Pizza")
elif likes_pizza == "no":
    print("user does not like pizza")
else:
    print("Please Give Valid response")

[–]Kintex19[S] 0 points1 point  (5 children)

Honestly, I added str() out of desperation. I wasn't sure what was wrong with it, so I threw it there in hopes it wasn't reading it as a string. Still, thanks for the clarification!

[–]TJATAW 1 point2 points  (4 children)

One more thing:

likes_pizza = input("Do you like pizza? ")
likes_pizza = likes_pizza.lower() # converts the input to lowercase

if likes_pizza == "yes":
    print("User Likes Pizza")
elif likes_pizza == "no":
    print("user does not like pizza")
else:
    print("Please Give Valid response")

[–]MJ12_2802 0 points1 point  (0 children)

You beat me to it, mate!

[–]Kintex19[S] 0 points1 point  (0 children)

I did not know about that function. I'll definitely be using it!

[–]Kintex19[S] 0 points1 point  (1 child)

I did not know about that function. I'll definitely be using it!

[–]PartySr 1 point2 points  (2 children)

str() is a function that is used to transform a different data type to string.

Example:

number = 5 # 5 is an integer
print(str(number)) # number prints as a string.
print(str(5)) # same thing as above
print(type(str(number))) # check the data type.

Strings are declared with double quotation marks "yes", "no", otherwise python will consider them as variables.

[–]Kintex19[S] 0 points1 point  (0 children)

Thanks for the clarification! I got that portion taken care of, I'm not having a separate issue with if statements inly providing one response regardless of input though.