Created
March 1, 2014 03:19
-
-
Save Arkitan/9284593 to your computer and use it in GitHub Desktop.
random words and names
This file contains 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
#!/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