Skip to content

Instantly share code, notes, and snippets.

@blammothyst
blammothyst / LPTHW ex35
Last active July 12, 2018 15:17
Code from Learn Python The Hard Way(.org) , 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.")
@blammothyst
blammothyst / LPTHWex 34
Last active August 29, 2015 13:56
Code from Learn Python The Hard Way (.org), ex 34
animals = ['bear', 'tiger', 'penguin', 'zebra']
bear = animals [0]
@blammothyst
blammothyst / LPTHW ex 33
Created February 27, 2014 20:14
Code from Learn Python The Hardway(.org), ex 33
i = 0
numbers = []
while i < 6:
print "At the top i is %d" % i
numbers.append(i)
i += 1
print "Numbers now: ", numbers
print "At the bottom i is %d" % i
@blammothyst
blammothyst / LPTHWex32
Last active August 29, 2015 13:56
Code from Learn Python The Hard Way (.org) ex 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 goes through a list
for number in the_count:
print "This is count %d" % number
#same as above
for fruit in fruits:
@blammothyst
blammothyst / LPTHWex31
Created February 27, 2014 20:17
Code from Learn Python The Hard Way (.org) ex 31
hairs = ['brown', 'blond', 'red']
eyes = ['brown', 'blue', 'green']
weights = [1, 2, 3, 4]
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 goes through a list
for number in the_count:
print "This is count %d" % number
@blammothyst
blammothyst / LPTHWex30
Created February 27, 2014 20:18
Code from Learn Python The Hard Way (.org) ex 30
people = 30
cars = 40
buses = 15
if cars > people:
print "We should take the cars."
elif cars < people:
print "We should not take the cars."
else:
print "We can't decide."
@blammothyst
blammothyst / LPTHWex29
Last active August 29, 2015 13:56
Code from Learn Python The Hard Way (.org) ex 29
people = 10
cats = 0
dogs = 5
if people < cats:
print "Too many cats! The world is doomed!"
if people > cats:
print "Not many cats! The world is saved!"
@blammothyst
blammothyst / LPTHWex26
Created February 27, 2014 20:19
Code from Learn Python The Hard Way (.org) ex 26
def break_words(stuff):
"""This function will break up words for us."""
words = stuff.split(' ')
return words
def sort_words(words):
"""Sorts the words."""
return sorted(words)
def print_first_word(words):
@blammothyst
blammothyst / LPTHWex25
Created February 27, 2014 20:20
Code from Learn Python The Hard Way (.org) ex 25
def break_words(stuff):
"""This function will break up words for us."""
words = stuff.split(' ')
return words
def sort_words(words):
"""Sorts the words."""
return sorted(words)
def print_first_word(words):
@blammothyst
blammothyst / LPTHWex24
Created February 27, 2014 20:21
Code from Learn Python the Hard Way (.org) ex 24
print "Let's practice everything."
print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'
poem = """
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explanation
\n\t\twhere there is none.
"""