Skip to content

Instantly share code, notes, and snippets.

@iamshadmirza
Created February 19, 2018 12:03
Show Gist options
  • Save iamshadmirza/9677d473902bc98c6000feed164280cd to your computer and use it in GitHub Desktop.
Save iamshadmirza/9677d473902bc98c6000feed164280cd to your computer and use it in GitHub Desktop.
Interacting with python
import random
def mainfunction():
while True:
rnum = random.randrange(1,4)
cpuschoice = numtochoice(rnum)
userscoice = input("Choose between stone, paper and scissor\n")
print('Cpu has choosen : ', cpuschoice)
print(decision(userscoice.lower(), cpuschoice))
def numtochoice(num):
switcher = {
1:'stone',
2:'paper',
3:'scissor'
}
return switcher.get(num)
def decision(user, cpu):
result = 'you lose'
if cpu=='stone' :
if user=='paper' :
result = 'you win'
elif cpu=='paper' :
if user=='scissor' :
result= 'you win'
elif cpu == 'scissor' :
if user == 'stone' :
result = 'you win'
if cpu == user :
result = 'it was a draw'
return result
mainfunction()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment