Difference between revisions of "CSC111 Lab 5 Solutions 2014"
(Created page with "--~~~~ ---- =Solution Programs for Lab #5= (will be released after the last lab section of the week) <!-- <br /> <source lang="python"> # lab5 solution programs (loops) # D. T...") |
|||
Line 2: | Line 2: | ||
---- | ---- | ||
=Solution Programs for Lab #5= | =Solution Programs for Lab #5= | ||
− | + | ||
− | |||
<br /> | <br /> | ||
<source lang="python"> | <source lang="python"> | ||
Line 138: | Line 137: | ||
blockingPlay( sound ) | blockingPlay( sound ) | ||
</source> | </source> | ||
− | + | ||
<br /> | <br /> | ||
<br /> | <br /> |
Revision as of 16:48, 27 February 2014
--D. Thiebaut (talk) 21:37, 25 February 2014 (EST)
Solution Programs for Lab #5
# lab5 solution programs (loops)
# D. Thiebaut
# single For-Loops
"""
for i in range( 3, 8 ):
print( i, end=" ")
print()
for i in [3, 4, 5, 6, 7]:
print( i, end=" " )
print()
for i in range( 4, 20+1, 2 ):
print( i, end=" " )
print()
for i in range( -3, 19+1, 2 ):
print( i, end=" " )
print()
start = int( input( "start where? " ) )
end = int( input( "end where? " ) )
if start <= end:
for i in range( start, end+1 ):
print( i, end=" " )
else:
for i in range( start, end-1, -1 ):
print( i, end=" " )
print()
for i in range( 11 ):
print( "%s%s----%s%s" % ( i*'*', i*'..', i*'-', i*'??' ) )
"""
# Nested For-Loops
for i in range(4):
for j in range( i+1 ):
print( "*", end="" )
print()
print()
for i in range( 4-1, 0-1, -1):
for j in range( i+1 ):
print( "*", end="" )
print()
print()
for i in range(4):
print( ' ' * (3-i), end="" )
for j in range( i+1 ):
print( "*", end="" )
print()
print()
for i in range(4-1, 0-1, -1):
print( ' ' * (3-i), end="" )
for j in range( i+1 ):
print( "*", end="" )
print()
print()
count = 1
for i in range(4-1, 0-1, -1):
print( ' ' * (3-i), end="" )
for j in range( i+1 ):
print( count, end="" )
count = count + 1
print()
print()
# JES Program
# JES program to take a sound file and play with it
# D. Thiebaut
#
file = pickAFile()
sound = makeSound( file )
blockingPlay( sound )
# get start index for clearing
startIndex = 13393 # index just before "the force..."
# get the number of samples in the sound file
noSamples = getLength( sound )
# clear all the samples from startIndex to end:
for i in range( startIndex, noSamples ):
setSampleValueAt( sound, i, 0 )
# play sound again
#blockingPlay( sound )
# Copy "remember" to the end of itself in the waveform
rememberLength = startIndex # that's the length of the word "remember"
for i in range( 0, startIndex ):
value = getSampleValueAt( sound, i )
setSampleValueAt( sound, i+rememberLength, value )
# play sound: "remember, remember"
blockingPlay( sound )
# get the original sound again
# and clear all but the word "remember"
sound = makeSound( file )
blockingPlay( sound )
startIndex = 13393 # index just before "the force..."
noSamples = getLength( sound )
# clear all the samples from startIndex to end:
for i in range( startIndex, noSamples ):
setSampleValueAt( sound, i, 0 )
# overlap remember on top of itself, starting at Index 6000
# which is roughly half the length of the word
endOfRemember = 13393
offset = 6000
for i in range( endOfRemember, 0, -1 ):
sourceValue = getSampleValueAt( sound, i)
destValue = getSampleValueAt( sound, i+offset )
setSampleValueAt( sound, i+offset, sourceValue + destValue )
blockingPlay( sound )