Skip to content

Instantly share code, notes, and snippets.

@Arkitan
Created March 1, 2014 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arkitan/9284593 to your computer and use it in GitHub Desktop.
Save Arkitan/9284593 to your computer and use it in GitHub Desktop.
random words and names
#!/usr/local/bin/python3.3
import random #this imports the random function to python
words = 'rock paper scissors'.split() #this creates a list from the variable words for the computer to choose from.
names = 'Bill Alexis Thatcher Eric Jack Henry'.split() #this creates a list from the variable names for the computer to choose from
def getRPS(choice): #this defines a new function called getRPS with the parameter choice
choiceIndex = random.randint(0, len(choice) -1) #this picks a number at random from 0 to the number of words in the words list
return choice[choiceIndex] #this takes the random number from choiceIndex and places it in the square bracket so if choiceIndex were 0 it would return choice[0] which would become...rock, since rock is the first word in the list created in line 3
wordChoice = getRPS(words) #this calls the function getRPS, and has it act on the list called words
nameChoice = getRPS(names) #this calls the function getRPS, and has it act on the list called names
print (wordChoice) #this prints the choice of word that the computer made.
print (nameChoice) #this prints the choice of name that the computer made.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment