Skip to content

Instantly share code, notes, and snippets.

@blammothyst
blammothyst / LPTHWex21
Created February 27, 2014 20:22
Code from Learn Python the Hard Way (.org) ex 21
def add(a, b):
print "ADDING %d + %d" % (a, b)
return a + b
def subtract(a, b):
print "SUBTRACTING %d - %d" % (a,b)
return a - b
def multiply(a, b):
print "MULTIPLYING %d * %d" % (a, b)
@blammothyst
blammothyst / LPTHWex20
Created February 27, 2014 20:22
Code from Learn Python the Hard Way (.org) ex 20
def add(a, b):
print "ADDING %d + %d" % (a, b)
return a + b
def subtract(a, b):
print "SUBTRACTING %d - %d" % (a,b)
return a - b
def multiply(a, b):
print "MULTIPLYING %d * %d" % (a, b)
@blammothyst
blammothyst / LPTHWex13
Created February 27, 2014 20:23
Code from Learn Python The Hard Way(.org) ex 13
from sys import argv
script, first, second, third = argv
print "The script is called:", script
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third
name = raw_input("name? ")
snark = " good one %s" % "huh"
print name + snark
@blammothyst
blammothyst / LPTHWex11
Created February 27, 2014 20:24
Code from Learn Python the Hard Way(.org) ex 11
print "How old are you?",
age = raw_input ()
print "How tall are you?",
height = raw_input ()
print "How much do you weight?",
weight = raw_input ()
print "So you're %r old, %r tall and %r heavy." % (
age, height, weight)
@blammothyst
blammothyst / LPTHWex17
Created February 27, 2014 20:24
Code from Learn Python the Hard Way(.org) ex 17
from sys import argv
from os.path import exists
script, from_file, to_file = argv
print "Copying from %s to %s" % (from_file, to_file)
#we could do these two on one line too, how?
in_file = open(from_file)
indata = in_file.read()
print "The input file is %d bytes long" % len(indata)
print "Does the output file exist? %r" % exists(to_file)
@blammothyst
blammothyst / LPTHWex16
Created February 27, 2014 20:25
Code from Learn Python the Hard Way(.org) ex 16
from sys import argv
script, filename = argv
print "We're going to erase %r." % filename
print "If you don't want that, hit CTRL-C (^C)."
print "If you do want that, hit RETURN."
raw_input("?")
print "Opening the file..."
@blammothyst
blammothyst / LPTHWex15
Created February 27, 2014 20:26
Code from Learn Python the Hard Way(.org) ex 15
#says what we are opening from where
from sys import argv
#here's what the two things we are importing will be
script, filename = argv
#variable txt means open that file
txt= open(filename)
#uses modulus to call out the filename
print "Here's your file %r:" % filename
#prints the file
print txt.read()
@blammothyst
blammothyst / LPTHWex14
Created February 27, 2014 20:27
Code from Learn Python the Hard Way(.org) ex 14
from sys import argv
script, user_name = argv
prompt = 'type that shit out son! '
print "Hi%s, I'm the %s script." % (user_name, script)
print "I'd like to ask you a few questions."
print "Do you like me %s?" % user_name
likes = raw_input(prompt)
print "Where do you live %s?" % user_name
@blammothyst
blammothyst / LPTHWex13
Created February 27, 2014 20:27
Code from Learn Python the Hard Way(.org) ex 13
from sys import argv
script, first, second, third = argv
print "What's this app's name?", script
print "What's your name human?", first
print "How tall you at?", second
print "What it weigh? (the it is you)", third
print "wait what is your name? ",
name = raw_input ()
@blammothyst
blammothyst / LPTHWex12
Created February 27, 2014 20:28
Code from Learn Python the Hard Way(.org) ex 12
y = raw_input("Name? ")
age = raw_input("How old are you? ")
height = raw_input("How tall are you? ")
weight = raw_input("How much do you weigh? ")
print "So, you're %r old, %r tall and %r heavy." % (
age, height, weight)