Can someone assist, what's wrong with this code? I'm a rookie in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can someone assist, what's wrong with this code? I'm a rookie in python

dinner=input("What did you eat") if dinner=food: print("Keep on eating") else: print("The program has ended")

22nd Jun 2017, 12:34 PM
Sizwe Khumalo
Sizwe Khumalo - avatar
4 Answers
+ 6
There are two things you need to fix. First, if food is a string, put it in quotes(""). Next, when making a comparison, you have to use a double equal sign. So line 2 of your program should look like this: if dinner=="food": Let me know if this helps!
22nd Jun 2017, 12:37 PM
Caleb Jore
Caleb Jore - avatar
+ 5
if dinner == "food": = is assignment operator == is used to check equality
22nd Jun 2017, 12:37 PM
Da' BO$
Da' BO$ - avatar
+ 2
YOU SHOULD USE == IN THE PLACE OF = =(is equal to) is used for assigning the values to a variable and == is used to compare the value of variables ^°,,°^
22nd Jun 2017, 1:11 PM
Robin sharma
Robin sharma - avatar
+ 1
Thank you. It worked like a charm.
22nd Jun 2017, 12:42 PM
Sizwe Khumalo
Sizwe Khumalo - avatar