DrJonSmith
Posts: 6
Joined: Sun Jan 04, 2015 12:39 am

My Python Code Does Not Work

Sun Jan 04, 2015 12:55 am

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
Last edited by DrJonSmith on Sun Jan 04, 2015 11:17 pm, edited 2 times in total.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: My Python Code Dose Not Work

Sun Jan 04, 2015 3:13 pm

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.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
joan
Posts: 14936
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: My Python Code Dose Not Work

Sun Jan 04, 2015 3:38 pm

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.

DrJonSmith
Posts: 6
Joined: Sun Jan 04, 2015 12:39 am

Re: My Python Code Does Not Work

Tue Jan 13, 2015 5:09 am

Thank You all for your help all works well.
DrJonSmith

Return to “Python”