Skip to content

Instantly share code, notes, and snippets.

@Arkitan
Arkitan / gist:10922451
Created April 16, 2014 19:16
Traceback (most recent call last): File "python", line 51, in <module> File "python", line 48, in get_class_average File "python", line 22, in average TypeError: unsupported operand type(s) for +: 'int' and 'str'
lloyd = {
"name": "Lloyd",
"homework": [90.0, 97.0, 75.0, 92.0],
"quizzes": [88.0, 40.0, 94.0],
"tests": [75.0, 90.0]
}
alice = {
"name": "Alice",
"homework": [100.0, 92.0, 98.0, 100.0],
"quizzes": [82.0, 83.0, 91.0],
#!/usr/local/bin/python3.3
import random
grep_a = {}
grep_b = {}
grep_c = {}
offspring = {}
dom_colors = 'red yellow green blue orange white brown black violet'.split()
rec_colors = 'indigo pink magenta khaki crimson gray turquoise gold silver'.split()
parts = 'eyes fur ears tail claws paws whiskers crest'.split()
dom_fur_accents = 'stripes spots'.split()
>>> spam = ['first', 'second', 'last']
>>> spam
['first', 'second', 'last']
>>> spam.sort()
>>> spam
['first', 'last', 'second']
>>> spam.append(1)
>>> spam
['first', 'last', 'second', 1]
>>> spam.sort()
@Arkitan
Arkitan / gist:9551254
Created March 14, 2014 16:29
Why does this jump to the game is over whenever its the computers turn?
#!/usr/local/bin/python3.3
#Tic Tac Toe
import random
def drawBoard(board):
print(' | |')
print(' ' + board[7] + ' | ' + board[8] + ' | ' + board[9])
print(' | |')
print('-----------')
@Arkitan
Arkitan / randomwordsandnames
Created March 1, 2014 03:19
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