[Tutor] Invalid Syntax Error

Yanlei Peng pylmsn at gmail.com
Wed Oct 23 09:44:07 EDT 2019


I'd like to add one more thing in addition to Alan and Cameron's comments:

> print ("Welcome to the Video Game Selector!")
> print ("Please decide between fps, sports, rpg or battle royale!")
> genre = input("Please enter your preferred genre of video games: ")
> if result = ("fps"):

You need to change all of your script where you used "result" to "genre",
because you were defining the input to read in "genre", not "result" ....

Best,
Yanlei

On Tue, Oct 22, 2019 at 6:47 PM Alan Gauld via Tutor <tutor at python.org>
wrote:

> On 16/10/2019 04:24, Tyson Barber wrote:
>
> > little simple Python code! In the code however there is a syntax error
> > (highlighted in yellow) and I was wondering if it was because I had to
> > declare it as a string? I was taught that it was automatically declared
> as
> > a string so I do not know where I went wrong?
>
> We can't see the colours because the list converts it to plain text.
> That's why you need to paste the entire error message into the mail.
> It tells us exactly what is wrong and where.
>
> > print ("Welcome to the Video Game Selector!")
> > print ("Please decide between fps, sports, rpg or battle royale!")
> > genre = input("Please enter your preferred genre of video games: ")
> > if result = ("fps"):
>
> You are doing an assignment to result. You should be doing a comparison
>
> if result == "fps":
>
> Also notice you don't need the parens.
>
>
> >     print ("Call of Duty MW, Battlefield V, Fallout 76, Gears of War 5")
> > elif result = ("sports"):
> >     print ("NBA 2K20, NHL 20, Madden 20, FIFA 20")
> > elif result = ("rpg"):
> >     print ("Skyrim, The Witcher, World of Warcraft")
> > elif result = ("battle royale"):
> >     print = ("Fortnite, APEX Legends, PUBG")
>
> And here you replace the print function with your data.
> While it is legal Python code it is a very bad idea because
> you will no longer be able to use print()...!
>
> I assume you just wanted to print the string?
>
>     print("Fortnite, APEX Legends, PUBG")
>
> > else:
> >     print = ("Sorry, that is not in the database.\n Try using a
> keyword!")
>
> Same here...
>
>
> HTH
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list