from random import * #user picks rock, paper, or scissors userpick = raw_input("type R for rock, P for paper, or S for scissors") #computer picks rock, paper, or scissors def comppick(number_in, letter_out): #print("hello") if(number_in is 1): #print("in1") letter_out = 'R' return letter_out if(number_in is 2): #print("in2") letter_out = 'P' return letter_out if(number_in is 3): #print("in3") letter_out = 'S' return letter_out #compare user (R,S,P) to computer (R,S,P) def compare(user, computer): if (user is 'R' and computer is 'P'): return "user wins!" if (user is 'R' and computer is 'S'): return "user wins!" if (user is 'R' and computer is 'R'): return "tie!" if (user is 'P' and computer is 'R'): return "user loses:(" if (user is 'P' and computer is 'P'): return "tie!" if (user is 'P' and computer is 'S'): return "user loses:(" if (user is 'S' and computer is 'S'): return "tie!" if (user is 'S' and computer is 'P'): return "user wins!" if (user is 'S' and computer is 'R'): return "user loses:(" comprandnum = randint(1,3) completter = '' #print(userpick) #print(comppick(comprandnum, completter)) #call on compare function with user and computer inputs, to print winner print '\n' print("user had " + userpick + ", and computer had " + comppick(comprandnum, completter) + " ... " + compare(userpick, comppick(comprandnum, completter)))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question