i have been trying to make a python rock paper scissors game with my limited python knowledge but good understanding of computer/ programming logic. here is my code:
def Main():
from random import randint
global computerChoice
global userChoice
print "Ok, let's play 3 rounds."
for i in range(3):
userChoice = raw_input("Rock, paper, or scissors? ")
computerChoice = randint(1,3)
if userChoice == "Rock" or "rock":
userChoice = 1
choiceCompare()
elif userChoice == "Paper" or "paper":
userChoice = 2
choiceCompare()
else:
userChoice = 3
choiceCompare()
def choiceCompare():
global userChoice
global computerChoice
if userChoice == computerChoice:
print "I chose the same thing! It's a draw!"
elif userChoice != computerChoice:
if userChoice == 1:
if computerChoice == 2:
print "Yes! I chose paper, you lost!"
elif computerChoice == 3:
print "Dang. I chose scissors, you win."
elif userChoice == 2:
if computerChoice == 1:
print "Man. I chose rock, you win."
elif computerChoice == 3:
print "I chose scissors, you loose!"
else:
if computerChoice == 1:
print "Ha! I chose rock, you loose."
elif computerChoice == 2:
print "Aww, man! I chose paper, you win."
if __name__ == "__main__":
Main()
when i run it, i get completely wrong outputs like this:
Ok, let's play 3 rounds.
Rock, paper, or scissors? paper
I chose the same thing! It's a draw!
Rock, paper, or scissors? paper
I chose the same thing! It's a draw!
Rock, paper, or scissors? paper
Dang. I chose scissors, you win.
or this:
Ok, let's play 3 rounds.
Rock, paper, or scissors? scissors
Yes! I chose paper, you lost!
Rock, paper, or scissors? scissors
Yes! I chose paper, you lost!
Rock, paper, or scissors? scissors
Dang. I chose scissors, you win.
however, rock seems to be working fine:
Ok, let's play 3 rounds.
Rock, paper, or scissors? rock
Dang. I chose scissors, you win.
Rock, paper, or scissors? rock
I chose the same thing! It's a draw!
Rock, paper, or scissors? rock
Yes! I chose paper, you lost!
can anyone tell me what they think is wrong? thanks in advance, Liam.
P.S. i think there is something wrong with my choiceCompare function in the nested if statements. I'm not quite sure what though. also, ignore the automatic coloring in the bits where i copied the text from the program running, as they are not actually python code but text from the program.