Write a function that takes in a picture and does something to each pixel.
That's right, CS is creative. Do anything you want to the pixel.
(Hmm) Now take your function from the previous part and modify it so that
it only modifies everything that's at least 20 pixels away from the edges
(Hint: use ranges)
(Hmm, hmm) Now take that function and modify it so that it only modifies
the pixels that are within 100 pixels of the top-left corner (Hint: use the distance
formula and an if statement)
Write a function that takes in a picture and flips the whole thing
horizontally
Write a function that takes in a picture and flips the whole thing
vertically (Don't write a new function, just modify your code from the
previous problem)
(Hmm) Write a function that takes in a picture and flips the top half of
the picture vertically and the bottom half horizontally.
Write a function that takes in a directory and outputs 100 frames to that
directory called "frame00.jpg", "frame01.jpg", ..., "frame99.jpg". The movie
is just a 50 pixel by 50 pixel picture that steadily fades from black to lime
green over the course of the 100 frames.
(Hmm) Write a function (100 frames, takes in a directory, you know the
routine now), and makes a movie. The frames are 100 pixels by 100 pixels with
a black background with a single white pixel that travels from the bottom left
corner to the top right corner over the course of the 100 frames. (Hint: think
of drawing a pixel as drawing a rectangle with width and height of 1. This is
also very much like the tickertape problem.)
Write a function that takes in a directory. The function will print out
the following information:
How many pictures (.gif, .jpg, .png, .bmp) are in the directory.
How many text documents (.txt, .rtf, .doc) are in the directory.
How many python files(.py) are in the directory.
>>>
yeehaw(r"C:\documents and settings\Blake O'Hare\Desktop") Pictures:
2 Text Documents: 9375390 Python Files:
20035
Extra cool points: Write a function called avgFileSize that takes
in a directory and returns the average file size in terms of Megabytes. (Yes,
we've taught you everything you need to know to be able to do this.)
<ul> <li>Scientists link donuts
with obesity.</li> <li>GT students are the happiest
according to Princeton Review.</li> <li>Microsoft goes open
source.</li> </ul>
</body> </html>
Suppose
this page could be found at http://www.blake.com/news.html. Write a function
that goes to this page and returns a list of all the headlines.
Write a function called flipLeft that takes in a sound and reverses
the first half only.
Write a function called fadeAway that takes in a 22kHz sound and
fades the last second to silence. You can assume that the sound passed in will
be more than 1 second in length.
Let's imagine that you are a CS1315 TA and you are
sorting completed quizzes by the students' recitations. Several
quiz-takers did not write their recitation time next to their gtg numbers.
Fortunately, you have a file named students.txt in your JES directory. The
format of the file is pound sign, gtgnum, backslash, student name, backslash, TA
names, backslash, recitation day, backslash, and recitation time. (You may assume
that gtg numbers, names, and times won't have backslashes in them.) An exert
from the file might look like this:
#gtg123a/George P. Burdell/Brittany, Bobby/Wednesday/6:00-7:30
#gte444q/Howard T. Duck/Swati, Blake/Wednesday/4:00-6:30
#gtg563b/Mickey M. Mouse/Brittany, Bobby/Wednesday/6:00-7:30
Write a function called recitation that will take a gtgnum
in a string as input. If that gtgnum is found in the contacts file, print the
recitation day and time of the student. If it is not found, print "Not Found." So,
if you executed breakout("gte444q") for the above file, you would get
printed out "Wednesday/1:30-3:00"
You may want to use these programs from lecture as reference.
def findSequence(seq):
sequencesFile = getMediaPath("parasites.txt")
file = open(sequencesFile,"rt")
sequences = file.read()
file.close()
# Find the sequence
seqloc = sequences.find(seq)
#print "Found at:",seqloc
if seqloc != -1:
# Now, find the ">" with the name of the sequence
nameloc = sequences.rfind(">",0,seqloc)
#print "Name at:",nameloc
endline = sequences.find("\n",nameloc)
print "Found in ",sequences[nameloc:endline]
if seqloc == -1:
print "Not found"
def findTemperature():
weatherFile = getMediaPath("AtlantaWeather1.html")
file = open(weatherFile,"rt")
weather = file.read()
file.close()
# Find the Temperature
humloc = weather.find("Humidity")
if humloc != -1:
# Now, find the "," where the temp starts
temploc = weather.rfind(",",0,humloc)
endline = weather.find("<",temploc)
print "Current temperature:",weather[temploc+1:endline]
if humloc == -1:
print "They must have changed the page format -- can't find the temp"
(I) Your mother shows you this cool new
image processing program she bought. "I can finally get rid of red-eye!" When
she clicks the red-eye removal button, she:
Draws a circle with her mouse around the red area in the eye.
Then clicks on a palette of colors of what the eye color should be.
And all the red is replaced with the selected color.
She says,
"How did that work? That's amazing. How can the computer figure out what part is
red?" Answer your mother's questions, (i) How did the red get replaced by the
selected color? and (b) how did the computer know what part was
red?
(II) You have a new computer that seems to connect to the
Internet, but when you try to go to http://www.cnn.com you get a "Not Found"
error. You call tech support, and they tell you to try to go to
http://64.236.24.20 That works. Now both you and the Tech know what's wrong
with your computer's settings. What isn't working properly since you can get to
a site via the Internet but can't get the domain name www.cnn.com to be
recognized?
(III) Your father calls you. "My tech support people are
saying that the company website is down because the database program is broken.
What does the database have to do with our company website?" You explain to
him how databases can be integral to running large websites. Explain both (a)
how the website comes to be authored through the database and (b) how the HTML
is actually created.
You're thinking about adding something to your
HTML home page generator that will make random, relevant comments about the
weather depending on the temperature.
If it's going to be less than 32, you want to insert either "Watch out for
ice!" or "Did I move North?!?"
If it's going to be between 32 and 50, you want to insert either "I can't
wait for winter to be over!" or "Come on, Spring!"
If it's over 50 but less than 80, you want to insert either "It's getting
warmer!" or "Light jacket or less weather."
If it's over 80, you want to insert either "FINALLY! Summer!" or "Time to
go swimming!"
Write a function named weathercomment that
will take a temperature as input and return one of the phrases randomly. In
other words, you want to use the temperature to decide which are the relevant
phrases, then pick one randomly from there.
You might recall these
programs from class and exam review as examples. The top one generates gendered
sentences, and the bottom one uses return to return a sentence to be inserted
into a homepage.
import random
def sentence(x):
nounsM = ["Mark", "Adam", "Larry", "Jose", "Matt", "Jim"]
nounsF = ["Angela", "Laura", "Meghan", "Mary"]
verbs = ["runs", "skips", "sings", "leaps", "jumps", "climbs", "argues", "giggles"]
phrases = ["in a tree", "over a log", "very loudly", "around the bush", "while reading the Technique"]
phrases = phrases + ["very badly", "while skipping","instead of grading", "while typing on the CoWeb."]
if x =="M":
print random.choice(nounsM), random.choice(verbs), random.choice(phrases)
if x=="F":
print random.choice(nounsF), random.choice(verbs), random.choice(phrases)
import random
def sentence():
nouns = ["Mark", "Adam", "Angela", "Larry", "Jose", "Matt", "Jim"]
verbs = ["runs", "skips", "sings", "leaps", "jumps", "climbs", "argues", "giggles"]
phrases = ["in a tree", "over a log", "very loudly", "around the bush", "while reading the Technique"]
phrases = phrases + ["very badly", "while skipping","instead of grading", "while typing on the CoWeb."]
#print random.choice(nouns), random.choice(verbs), random.choice(phrases),"."
return random.choice(nouns)+" "+random.choice(verbs)+" "+random.choice(phrases)+"."
>>> downUp("Hello")
Hello
ello
llo
lo
o
lo
llo
ello
Hello
Here's the code that we wrote that did it:
def downUp(word):
if len(word)==1:
print word #Print #1
return
print word #Print #2
downUp(word[1:])
print word #Print #3
a. Which print statement prints the ever-shortening ("on the
way down") words? Which print statement prints the single letter in
the middle? Which print statement prints the longer-growing words? b. At
most, how many copies of downUp are running at once with the input
"Hello"? c. How would you modify downUp to create upDown that
works like this:
>>> upDown("Hello")
Hello
Hell
Hel
He
H
He
Hel
Hell
Hello