Page 1 of 1

My Python Code Does Not Work

Posted: Sun Jan 04, 2015 12:55 am
by DrJonSmith
Hello

I have been following tutorial online about making a text based game. The code does not work if any one knows how to fix this or a tutorial that works would be most appreciated here is my code:

try: par = raw_input ('What direction do you want to go in? n = north...')

if par=='north' or par=='n':
print ('you are going north')

elif par=='south' or par=='s':
print ('you are going south')

the top if has the invalid syntax and gets highlighted red.

Thankyou
DrJonSmith

Re: My Python Code Dose Not Work

Posted: Sun Jan 04, 2015 3:13 pm
by elParaguayo
DrJonSmith, can you please post your full code inside code tags (see the post at the top of the python forum). We need to see your indentation add this is vital for python code.

Re: My Python Code Dose Not Work

Posted: Sun Jan 04, 2015 3:38 pm
by joan
e.g. like

Code: Select all

#!/usr/bin/env python

try:
   par = raw_input ('What direction do you want to go in? n = north...')

   if par=='north' or par=='n':
      print ('you are going north')

   elif par=='south' or par=='s':
      print ('you are going south')

finally:
   pass
The above code does what I think you are trying to do.

Re: My Python Code Does Not Work

Posted: Tue Jan 13, 2015 5:09 am
by DrJonSmith
Thank You all for your help all works well.
DrJonSmith