Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite+ 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")
4 Réponses
+ 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!
+ 5
if dinner == "food":
= is assignment operator
== is used to check equality
+ 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
^°,,°^
+ 1
Thank you. It worked like a charm.