Rock Paper Scisors
What is rock paper scissors?
import random
user_score=0
comp_score=0
user_choice=""
comp_choice=""
def Choice_To_Number(choice):
rps={'rock':0,'paper':1,'scissor':2}
return rps[choice]
pass
def Number_To_Choice(choice):
rps={0:'rock',1:'paper',2:'scissor'}
return rps[choice]
pass
def random_comp_choice():
ch=['rock','paper','scissor']
return ch[random.randint(0,len(ch))]
def result(human_choice,Comp_choice):
global user_choice
global comp_choice
user=Choice_To_Number(human_choice)
comp=Choice_To_Number(Comp_choice)
if user==comp:
print("Draw")
elif (user-comp)%3==1:
print("You win")
else:
print("Computer Wins")
def rock():
global user_choice
global comp_choice
user_choice='rock'
comp_choice=random_comp_choice()
print('user choice: '+user_choice)
print('comp choice: '+comp_choice)
result(user_choice,comp_choice)
def paper():
global user_choice
global comp_choice
user_choice='paper'
comp_choice=random_comp_choice()
print('user choice: '+user_choice)
print('comp choice: '+comp_choice)
result(user_choice,comp_choice)
def scissor():
global user_choice
global comp_choice
user_choice='rock'
comp_choice=random_comp_choice()
print('user choice: '+user_choice)
print('comp choice: '+comp_choice)
result(user_choice,comp_choice)
while True:
print("enter 1 for rock")
print("enter 2 for paper")
print("enter 3 for scissor")
i=int(input("enter yor choice: "))
if i==1:
rock()
elif i==2:
paper()
elif i==3:
scissor()
else:
break