Skip to content

Instantly share code, notes, and snippets.

@dvtate
Created June 9, 2016 22:49
Show Gist options
  • Save dvtate/d5fb13136cea30cde4b43aab89b7315c to your computer and use it in GitHub Desktop.
Save dvtate/d5fb13136cea30cde4b43aab89b7315c to your computer and use it in GitHub Desktop.
rock paper sicissors game running example: https://trinket.io/python/9ef5bd227b
#rock paper scissors
#DV Tate Testa
import random;
def randomChoice():
options = ["rock","paper","scissors"];
rChoice = random.randint(0,2);
return(options[rChoice]);
#main
print("r=rock\np=paper\ns=scissors\nq=quit\n");#explain game
hands = {'r':'rock', 'p':'paper', 's':'scissors'};#what are choices what do the mean
again = True;
while again:
hand = raw_input('Your Choice:');
comp = randomChoice();
if hands.has_key(hand) and hands[hand]==comp:
print('sorry, we both chose %s'%(comp));
elif hand=='r':
if comp=='scissors':
print("Your rock beat my %s"%(comp));
else:
print('My %s beat your %s'%(comp,hands[hand]));
elif hand=='p':
if comp=='rock':
print("Your paper beat my %s"%(comp));
else:
print('My %s beat your %s'%(comp,hands[hand]));
elif hand=='s':
if comp=='paper':
print("Your scissors beat my %s"%(comp));
else:
print('My %s beat your %s'%(comp,hands[hand]));
elif hand=='q':
again=False;
print("GAME OVER");
elif hand=='':
print("Can't you type?");
else:
print("Sorry, I didn't understand %s."%(hand));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment