Skip to content

Instantly share code, notes, and snippets.

@blammothyst
blammothyst / LPTHWex7
Created February 27, 2014 20:32
Code from Learn Python the Hard Way (.org) ex 7
print "Mary had a little lamb."
print "Its fleece was white as %s." % 'snow'
print "And everywhere that Mary went."
print "." * 10 # what'd that do?
end1 = "C"
end2 = "h"
end3 = "e"
end4 = "e"
end5 = "s"
@blammothyst
blammothyst / LPTHWex8
Created February 27, 2014 20:30
Code from Learn Python the Hard Way (.org) ex 8
formatter= "%r %r %r %r"
print formatter % (1, 2, 3, 4)
print formatter % ("one", "two", "three", "four")
print formatter % (True, False, False, True)
print formatter % (formatter, formatter, formatter, formatter)
print formatter % (
"I had this thing.",
"That could type up right.",
"But it didn't sing.",
@blammothyst
blammothyst / LPTHWex9
Created February 27, 2014 20:29
Code from Learn Python the Hard Way(.org) ex 9
# Here's some new strange stuff, remember type it exactly.
days= "Mon Tue Wed Thu Fri Sat Sun"
months= "\nJan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"
print "Here are the days: ", days
print "Here are the months: ", months
print """
There's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.
Even 4 lines if we want, or 5, or 6.
@blammothyst
blammothyst / LPTHWex10
Created February 27, 2014 20:28
Code from Learn Python the Hard Way(.org) ex 10
print "I am 6'2\" tall." #escape double-quote inside string
print 'I am 6\'2" tall.' #escape single-quote inside string
tabby_cat = "\tI'm tabbed in."
persian_cat = "I'm split\non a line."
backslash_cat = "I'm \\ a \\ cat."
fat_cat = '''
I'll do a list:
\t* Cat food
\t* Fishies
@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)
@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 / 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 / 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 / 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 / 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)