def mystery1(filename): #reversing
source = makeSound(filename)
dest = makeSound(filename)
srcIndex = getLength(source)
for destIndex in range(1, getLength(dest) + 1):
srcSample = getSampleValueAt(source, srcIndex) #(source sound, location)
setSampleValueAt(dest, destIndex, srcSample) #(place to put sound, location to put it, sample)
srcIndex = srcIndex - 1
return dest
def mystery2(sound): #Normalizing
largest = 0
for s in getSamples(sound):
largest = max(largest, getSample(s) )
amplification = 32767.0 / largest
print "Largest sample value in original sound was", largest
print ”Amplification multiplier is", amplification
for s in getSamples(sound):
louder = amplification * getSample(s)
setSample(s, louder)
def mystery3(sound1, sound2): #blend 1
for sampleNmr in range(1, getLength(sound1)+1):
sample1 = getSampleValueAt(sound1, sampleNmr)
sample2 = getSampleValueAt(sound2, sampleNmr)
setSampleValueAt(sound2, sampleNmr, (sample1 + sample2)/2)
def mystery4(sound1, sound2): #blend 2
for index in range(1, getLength(sound1)
,2)
setSampleValueAt(sound1, index, sound2)
return sound1
How is sound represented to a computer?
Sample
amplitude- as a number
Nyquist Theorem
2x as many samples as max frequency(rate)
HTML
#says the file is html
#says you are talking about the title bar
My Title #puts "My Title" in the tile bar
#what will actually be in the document
#
#row
| column |
column2 in row1 |
|
#unordered list
#ordered list
- item 1
- item 2
...
#paragraph
#line break
#bold
#italics
Write a function that adds all the numbers in a list and returns the sum:
#Fill in the lines to the right with the output that will be generated by this function
def string_manipulate():
string = "Connecticut"
[C,o,n,n,e,c,t,i,c,u,t]
0 1 2 3 4.... 10
-11 -3-2-1
print len(string) 11
print min(string) C
print max(string) u
print string.count("n") 2
print string.count('n') 2
print string.replace("t","$") Connec$icu$
print string Connecticut
print string.replace("t","$",2) Connec$icu$
print "I am in" + " " + string #________________________________
print string.lower() connecticut
print string.upper() CONNECTICUT
print string.isupper() 0
print string.islower() 0
print string.capitalize() C
print string.swapcase() cONNECTICUT
string = "Connecticut"
print string.endswith("t") 1
print string.endswith("o") #________________________________
print string.startswith("c") #________________________________
print string.startswith("C") #________________________________
print string.startswith("s") #________________________________
print string.find("onn") 1
print string.find("ect") #________________________________
print string.find("cn") #________________________________
print string.rfind("t") 10
print string.find("z") -1
print string[3:7] nect # doesnt include 7
print string[0:7] Connect
print string[0:19] Connecticut
[ start : end BEFORE : increment ]
print string[4:] ecticut
print string[:2] Co
print string[-1: ] t
print string[:-1] Connecticu
print string[0::2] Cnetct
print string[ len(string)-1::-1] [10: END : Go backwards] tucitcennoC
print string[::-1] tucitcennoC
print string.isalpha() 1
print string.isdigit() 0
print string.split('n') ["Co","","ecticut"]
Modules Random, Time, Math, OS
Circumference of a cirlce
import time
import os
#will this work?
def circumference(radius):
import math
circum= 2 * math.pi * radius
return circum
#exp(x) e^x
#pow(x,y) x**y x^y
#sqrt(x)
#cos(x) ...
#math.pi
#dont do this --> math.pi()
#pi, e
Shuffle deck of cards, return 2
import random
deck = range(1,53)
random.shuffle(deck)
card = random.choice(deck)
#return card
return deck[0:2]
random.randint(1,100) #1 to 100
random.random() #0.0 to .9999999999999999999999
random.shuffle(list)
random.choice(list)
random.randrange(1,100) #1 to 99
What day is it?
def todaysDay():
import time
now = time.ctime()
return now[0:3]
#ctime 'Thu Apr 03 14:24:51 2008'
#gmtime (2008, 4, 3, 18, 24, 45, 3, 94, 0)
#time 1.20724708825E9
Count .jpg in a dir
#which imports?
def counter(dir)
import os
names = os.listdir(dir)
count = 0
for file in names:
if names.endswith(".jpg")
#What should I put here?
return count
#os.listdir(directory)
#os.sep
#STRINGS:
f=open("file.txt", "wt") #"rt"
f.write("this \n" ) # \t (tab) \n (new line)
lines = f.readlines()
lines[1].rfind("a")
f.close()