Skip to content

Instantly share code, notes, and snippets.

@adaptives
adaptives / ex16.py
Created September 14, 2011 06:32
Writing to a file in Python
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 want that hit RETURN."
raw_input("?")
@adaptives
adaptives / ex16.py
Created September 14, 2011 06:31
Writing to a file in Python
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 want that hit RETURN."
raw_input("?")
@adaptives
adaptives / ex15.py
Created September 12, 2011 11:52
LPTHW - Exercise 15
from sys import argv
script, filename = argv
txt = open(filename)
print "Here's your file %r:" % filename
print txt.read()
print "Type the filename again:"
@adaptives
adaptives / ex14.py
Created September 12, 2011 11:36
LPTHW - Exercise 14
#LPTHW Exercise 14
from sys import argv
script, user_name = argv
prompt = '> '
print "Hi %s, I'm the %s script." % (user_name, script)
print "I'd like to ask you a few questions."
@adaptives
adaptives / ex13.py
Created September 12, 2011 11:18
LPTHW - Exercise 13
#LPTHW - Exercise 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
@adaptives
adaptives / ex12.py
Created September 12, 2011 10:34
LPTHW - Exercise 12
#LPTHW Exercise 12
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)
@adaptives
adaptives / ex11.py
Created September 12, 2011 10:06
LPTHW - Exercise 11
#LPTHW Exercise 11
print "How old are you?",
age = raw_input()
print "How tall are you?",
height = raw_input()
print "How much do you weigh?",
weight = raw_input()
print "So, you're %r old, %r tall and %r heavy." % (age, height, weight)
@adaptives
adaptives / ex10.py
Created September 12, 2011 09:53
LPTHW - Exercise 10
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
\t* Catnip\n\t* Grass
"""
@adaptives
adaptives / ex8.py
Created September 12, 2011 07:34
LPTHW - Exercise 9
# Here's some new strange stuff, remember type it exactly.
days = "Mon Tue Wed Thu Fri Sat Sun"
months = "Jan\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.
@adaptives
adaptives / ex8.py
Created August 31, 2011 11:10
LPTHW - Exercise 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)
print formatter % (
"I had this thing.",
"That you could type up right.",
"But it didn't sing.",