[Tutor] Invalid Syntax Error

Cameron Simpson cs at cskk.id.au
Wed Oct 16 04:46:05 EDT 2019


On 15Oct2019 23:24, Tyson Barber <tysonwbarber at gmail.com> wrote:
>I am trying to make a video game selector for my friend since he never
>knows what to play and I thought it would be interesting to give him a
>little simple Python code! In the code however there is a syntax error
>(highlighted in yellow)

As mentioned, this is a plain text list. We don't see any colour 
highlighting you supply.

>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?

You don't have to declare variables in Python, and they do not have 
fixed types. Their _values_ have types though; a variable is a reference 
to a value.

To the code itself:

>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: ")

Ok, the return value from input() is a string. Which is fine.

>if result = ("fps"):

The primary problem here is that a single equals ("=") is for variable 
assignments. Comparison is spelt with two equals ("==") thus:

    if result == ("fps"):

You also do not need the brackets:

    if result == "fps":

>    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")

You don't want the "=" in the print call. print() is just a function 
call, so:

    print ("Fortnite, APEX Legends, PUBG")

>else:
>    print = ("Sorry, that is not in the database.\n Try using a 
>    keyword!")

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Tutor mailing list