Hi,
i have little problem here
i was trying to make rock,paper,scissor project
while running it
i got this error UnboundLocalError: local variable 'comp' referenced before assignment
what should i do to fix it ?
code:
from random import randint
#Computer draws hand.
def comp():
r=randint(1,3)
if r == 1:
hand = "rock"
if r == 2 :
hand = "paper"
if r == 3 :
hand = "scissor"
return hand
# who is the winner.
def whowin(you,comp):
if you == comp:
winner = "tie"
elif comp == ("rock" and you == "scissor") or comp == ("scissor" and you == "paper") or comp == ("paper" and you == "rock"):
winner = "comp"
else:
winner = "you"
return winner
# start
def play():
print "------welcome to my game------"
comp_wins = 0
you_wins = 0
tie_wins = 0
while True:
you = raw_input("Please choose rock or scissor or paper ")
you=you.lower()
comp = comp()
winner = whowin(you,comp)
if not you == "rock" or you == "paper" or you =="scissor":
print" invalid"
continue
play()
Thanks