2009 105

From XPUB & Lens-Based wiki

's morgens

Review Think Python Chapters 7 & 8

Additional Exercises for Chapter 7 - 8

ROT13 Exercise (8.12 from text book)

def rot_letter(l, num):
	# ord converts letters to numbers
	# chr converts numbers to letters
	
	if (l >= "a" and l <= "z"):
		lnum = ord(l)
		lnum = lnum + num
		znum = ord("z")
		
		if lnum > znum:
			lnum = lnum - 26
		if lnum < ord("a"):
			lnum += 26
		new_letter = chr(lnum)
	else:
		new_letter = l
		
	return new_letter

def rot_word(word, num):
	new_word = ""
	for letter in word:
		new_letter = rot_letter(letter, num)
		new_word += new_letter
	return new_word


#print rot_word("cheer", 7)
#print rot_word("yes", 2)
#print rot_word("bee", -3)

text = "How many turtles do you see?"
rtext = rot_word(text, 7)
print text
print rtext
print rot_word(rtext, -7)

's middags

Media Loops with Command Line Video Editing

import os

print "playing sample..."

cmd = "mplayer -ss 18:36 -endpos 2 debates.mp3"
os.system(cmd + "> /dev/null 2> /dev/null")

cmd = "mplayer -ss 18:35 -endpos 2 debates.mp3"
os.system(cmd + "> /dev/null 2> /dev/null")

cmd = "mplayer -ss 18:34 -endpos 2 debates.mp3"
os.system(cmd + "> /dev/null 2> /dev/null")

print "done"