0
print("-----ROCK, PAPER, SCISSORS-----")
import random

computer=random.randint(1,5)
user=int(input("Enter Your Choice:\n1=Rock\n2=Paper\n3=Scissors\n4=Lizzard\n5=Spoc\n"))

print("the computer has chosen",computer)

if computer==user:
    print("Tie Game")
elif computer==1 and user==3:
    print("Computer Wins")
elif computer==2 and user==1:
    print("Computer wins")
elif computer==3 and user==2:
    print("Computer wins")
elif computer==4 and user==3:
    print("Computer wins")
elif computer==4 and user==2:
    print("Computer wins")
elif computer==4 and user==1:
    print("Computer wins")
elif computer==5 and user==1:
    print("Computer wins")
elif computer==5 and user==2:
    print("Computer wins")
elif computer==5 and user==3:
    print("Computer wins")
elif computer==5 and user==4:
    print("Computer wins")
else:
    print("You win")

Thats my code. I have five possible choices. However, when i type in the number 10 for my choice, i automaticly get a 'You Win'. How do I add a range so I can only allow five choices.

DavalliTV
  • 65
  • 1
  • 9
  • have a look on this answer. might help a bit to understand: http://stackoverflow.com/questions/60208/replacements-for-switch-statement-in-python – vidriduch May 08 '15 at 15:07

2 Answers2

2

You would have to check that the user inputs a valid value, if they give you something that is not between 1 and 5, ask them for another number or something like that. Before you see who won, make sure both are playing the game the right way.

Eric Renouf
  • 13,950
  • 3
  • 45
  • 67
  • 1
    You already have a lot of if statements looking at the value the user gave you, just add some at the beginning to make sure the user's value is a valid one. – Eric Renouf May 08 '15 at 15:08
  • 1
    thxs again Eric ive just made my first major working code with the help of you – DavalliTV May 08 '15 at 15:13
  • @JackBond Hi, don't forget to mark an answer as accepted if it successfully solved your question. Welcome to StackOverflow! – Serlite May 08 '15 at 15:43
1
if user > 5:
    print "please choose again"
else:    
    if computer==user:
        print("Tie Game")
    elif computer==1 and user==3:
        print("Computer Wins")
    elif computer==2 and user==1:
        print("Computer wins")
    elif computer==3 and user==2:
        print("Computer wins")
    elif computer==4 and user==3:
        print("Computer wins")
    elif computer==4 and user==2:
        print("Computer wins")
    elif computer==4 and user==1:
        print("Computer wins")
    elif computer==5 and user==1:
        print("Computer wins")
    elif computer==5 and user==2:
        print("Computer wins")
    elif computer==5 and user==3:
        print("Computer wins")
    elif computer==5 and user==4:
        print("Computer wins")
    else:
        print("You win")
Lars Vine
  • 11
  • 2
  • Thanks for this. Even though I used the answer above to help me, I tried your code and it worked the exact same way. – DavalliTV Sep 29 '16 at 09:47