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

Gene Heskett gheskett at shentel.net
Tue Nov 22 02:43:34 EST 2016


On Monday 21 November 2016 22:20:40 Chris Angelico wrote:

> 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

I'm a fading 82 yo, and python dummy, but I think I see it.  In fact, I 
wrote a program to check for that and similar errors in my C code back 
in the late '80's. I called it cntx at the time.

Cheers, Gene Heskett
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page <http://geneslinuxbox.net:6309/gene>



More information about the Python-list mailing list