[Tutor] Invalid Syntax Error

Alan Gauld alan.gauld at btinternet.com
Wed Oct 16 04:29:50 EDT 2019


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



More information about the Tutor mailing list