Can somebody tell me what's wrong wrong with my code? I don't understand

Chris Angelico rosuav at gmail.com
Mon Nov 21 22:20:40 EST 2016


On Tue, Nov 22, 2016 at 2:10 PM,  <rmjbros3 at gmail.com> wrote:
> Hi! This is my first post! I'm having trouble understanding my code. I get "SyntaxError:invalid syntax" on line 49. I'm trying to code a simple text-based rpg on repl.it. Thank you for reading.
>
>
> elif raceNum==3:
>   print("Nice fur. I don't see too many of your kind 'round here. Maybe that's a good thing...")
>   print('')
>   classNum=int(input("What's your profession mate?")
>
> elif raceNum==4:             #this line has an error for some reason
>   print("Your a 'Mongo eh? I thought you lads were extinct...Just keep your tongue in ya mouth and we'll get along fine mate.")
>   classNum=int(input("What's your profession?"))

Welcome to the community! I've trimmed your code to highlight the part
I'm about to refer to.

One of the tricks to understanding these kinds of errors is knowing
how the code is read, which is: top to bottom, left to right, exactly
the same as in English. Sometimes, a problem with one line of code is
actually discovered on the next line of code. (Occasionally further
down.) When you get a syntax error at the beginning of a line, it's
worth checking the previous line to see if it's somehow unfinished.

Have a look at your two blocks of code here. See if you can spot a
difference. There is one, and it's causing your error.

I'm hinting rather than overtly pointing it out, so you get a chance
to try this for yourself. Have at it!

ChrisA



More information about the Python-list mailing list