Created
February 19, 2018 12:03
-
-
Save iamshadmirza/9677d473902bc98c6000feed164280cd to your computer and use it in GitHub Desktop.
Interacting with python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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