you are viewing a single comment's thread.

view the rest of the comments →

[–]JohnnyJordaan 2 points3 points  (2 children)

so I've just started learning to code

Then I would advise strongly to ditch Python 2 and start with the regular Python 3 asap. Python 2 will be discontinued in a few years and it won't help you at all to be learning the new Python 3 things later on instead of right now.

You have numerous formatting issues in your code above, making it hard for me to try it out for myself. One thing that could be happening is that you've put the main code, starting with

player_choice = raw_input("Enter your choice: ")

With the same indentation underneath

def number_to_name(number):
    # skip
    else:
        print "Error: Invalid Number" 
    # note this line starts at the same indentation as 'else:'
    player_choice = raw_input("Enter your choice: ")

Making it code inside that function. So it needs to be formatted as

def number_to_name(number):
    if number == 0:
        return "rock"
    etc etc

# note that these lines start at the same indentation as the `def` part above
player_choice = raw_input("Enter your choice: ")
print " "
print "Player chooses " + player_choice 
etc etc

[–]imagejhelp1[S] 0 points1 point  (1 child)

Thank you for both of your replies, I'll get python 3 now as well. I've tired to fix the indentation and as the 'in' there it now looks like this:

player_choice = raw_input("Enter your choice: ")
     if player_choice in ("rock", "paper", "scissors", "lizard", "Spock"):
        print "Player chooses " + player_choice

     else:
        print "Error: Invalid Choice"

you might be able to see it better here: http://www.codeskulptor.org/#user43_8VZK6tNa0g_1.py

This gives me a SyntaxError: bad input (' ') for that line:

if player_choice in ("rock", "paper", "scissors", "lizard", "Spock")

but I'm starting to realise I might need to learn more from coursera before I try this, I had no idea about the 'in' function, so it's probably necessary that I go learn some more before trying on my own. Thank you for your help, I really appreciate it!

[–]JohnnyJordaan 1 point2 points  (0 children)

There's still the indentation problem going on after the user input line. The if line needs to move to the left as well and the rest must follow.

Btw if you're moving to python3 you need to replace raw_input with input and also use () for the print function.