Skip to content

Instantly share code, notes, and snippets.

@adaptives
adaptives / ex43_game.py
Created September 30, 2011 16:44
LPTHW Exercise 44
# LPTHW Exercise 43
import random
""" This module contains classes which denote the Game and individual rooms of the game."""
class Game(object):
"""
This class represents the Game. It is what you would expect in a game
engine.
@adaptives
adaptives / ex43_game.py
Created September 30, 2011 09:39
LPTHW Exercise 43
# LPTHW Exercise 43
import random
""" This module contains classes which denote the Game and individual rooms of the game."""
class Game(object):
def __init__(self):
self.cmds = {}
self.cmds["rooms"] = "Prints the list of available rooms"
self.cmds["room"] = "Print the name of the current room. If followed by an argument then user will be taken to that room"
@adaptives
adaptives / ex42.py
Created September 29, 2011 11:56
LPTHW Exercise 42
# LPTHW Exercise 42
from sys import exit
from random import randint
class Game(object):
def __init__(self, start):
self.quips = [
"You died. You suck at this!",
@adaptives
adaptives / ex41.py
Created September 28, 2011 12:09
LPTHW Exercise 41
from sys import exit
from random import randint
def death():
quips = ["You died. You kinda suck at this.",
"Nice job, you died ...jackass.",
"Such a luser.",
"I have a small puppy that's better at this."]
print quips[randint(0, len(quips)-1)]
@adaptives
adaptives / ex40.py
Created September 28, 2011 10:03
LPTHW Exercise 40
# LPTHW Exercise 40
cities = {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville'}
cities['NY'] = 'New York'
cities['OR'] = 'Portland'
def find_city(themap, state):
if state in themap:
return themap[state]
@adaptives
adaptives / ex39.py
Created September 28, 2011 09:42
LPTHW Exercise 39
# LPTHW Exercise 39
ten_things = "Apples Oranges Crows Telephone Light Sugar"
print "Wait there's not 10 things in that list, let's fix that."
stuff = ten_things = ten_things.split(' ')
more_stuff = ["Day", "Night", "Song", "Frisbee", "Corn", "Banana", "Girl", "Boy"
]
@adaptives
adaptives / ex36.py
Created September 27, 2011 12:08
LPTHW Exercise 36
from sys import exit
import random
countries = [['India', 'New Delhi'], ['United States of America', 'New York'], ['Afghanistan', 'Kabul'], ['Australia', 'Canberra'], ['Austria', 'Vienna'], ['Cambodia', 'Phnom Penh']]
countries_answered = []
def get_random_country_and_capital():
randint = random.randint(0, countryCount-1)
country = countries[randint][0]
@adaptives
adaptives / ex35.py
Created September 27, 2011 10:11
LPTHW Exercise 35
from sys import exit
def gold_room():
print "This room is full of gold. How much do you take?"
next = raw_input("> ")
if "0" in next or "1" in next:
how_much = int(next)
else:
dead("Man, learn to type a number.")
@adaptives
adaptives / ex33.py
Created September 27, 2011 09:49
LPTHW Exercise 33
# LPTHW Exercise 33
i = 0
numbers = []
while i < 6:
print "At the top i is %d" % i
numbers.append(i)
i = i + 1
@adaptives
adaptives / ex32.py
Created September 27, 2011 09:28
LPTHW Exercise 32
#LPTHW Exercise 32
the_count = [1, 2, 3, 4, 5]
fruits = ['apples', 'oranges', 'pears', 'apricots']
change = [1, 'pennies', 2, 'dimes', 3, 'quarters']
# this first kind of for-loop does through a list
for number in the_count:
print "This is count %d" % number