New Semester
Started
Get
50% OFF
Study Help!
--h --m --s
Claim Now
Question Answers
Textbooks
Find textbooks, questions and answers
Oops, something went wrong!
Change your search query and then try again
S
Books
FREE
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Tutors
Online Tutors
Find a Tutor
Hire a Tutor
Become a Tutor
AI Tutor
AI Study Planner
NEW
Sell Books
Search
Search
Sign In
Register
study help
computer science
introduction to computing and programming in pytho
Introduction To Computing And Programming In Python A Multimedia Approach 4th Edition Mark J. Guzdial, Barbara Ericson - Solutions
The Web site https://musopen.org/ has copyright-free sheet music. Take any one of those songs and translate it into MIDI notes, and write a function to play it.
Challenging: Take any song you want and play it by using the recorded bassoon notes in the media folder, shifting them up and down in frequency to create the right notes.
Typically, one does not optimize a program (make it run faster or with less use of memory) until after it is running, well-debugged, and well-tested. (Of course, you still have to test again after each optimizing modification.) Here is an optimization that we could make to the adventure game.
A function like pickRoom is hard to read with all the nested if statements. It can be made clearer with appropriate use of comments to explain what each section of the code is doing—checking the room, then checking the possible directions in the room. Add comments to pickRoom to make it easier to
Add comments to all the methods, to make it easier for someone else to read the function.
Add another global variable for the player, called a hand. Make the hand initially empty. Change the description so that there is a “key” in the Living Room. If the player types the command key while in the Living Room, the key gets put in the hand. Now, if the player has the key when entering
Create the ability to go down from the Porch, to explore a secret underground world.
Add additional secret items to have in the player’s hand to allow different rooms to be accessed, such as a lantern to allow access to a tunnel under the Porch.
Add a “bomb” in the Dining Room. If the player types bomb in the Dining Room, the bomb goes in the hand. If the player types bomb in the upstairs where the Ogre is, the bomb is dropped and the Ogre is blasted to smithereens.
Add the ability for the player to win the game. When the player wins, the game should print what happened and exit the game. Perhaps finding the secret treasure room under the Porch would make the player win the game.
Room descriptions do not have to be wholly verbal. Play a relevant sound when the player enters a particular room. Use play, so that game play can continue while the sound is playing.
Room descriptions can be visual, as well as textual and auditory. Display a picture relevant to the room when the room is entered. For extra credit, only show a picture once, and if the room is reentered, repaint the picture to bring it back to the front again.
A source of possible error in this adventure game is that the names for the rooms appear in several places. If the Dining Room is spelled “DiningRoom” in one place and “DinngRoom” (missing the second “i”) in another place, the game won’t work correctly. The more rooms you add, and the
Currently, the user must get the case right when typing the directions. Use the lower() method on strings (introduced in Chapter 3) to make the input all in lowercase, so that both “North” and “north” will work as input.
Let’s start over with a new map. Below is a map of a castle.Create a new adventure game based on this map. Think Lord of the Rings or maybe Game of Thrones. The player should start on the drawbridge. Princess Room King's Room Sir Knight's Room Hallway Wizard's Room Kitchens Courtyard Stables Gate
In the castle game, the player must answer a riddle correctly or provide a password in order to pass through to the Courtyard. Add that to your game.
Games often have nonplayer characters (NPC) which are characters that are not controlled by the player. Add an EvilWizard to the castle game. When you first play the game, the Evil Wizard is in the Courtyard, and his description says that he is in the Courtyard, but then disappears. Every other
Use the in operator from Chapter 3 to provide some flexibility to the castle game. Allow the player in the Courtyard to go “north” or “up” to the upper Hallway, or “down” or “south” to return to the Courtyard from the Hallway.
Consider this program:If we execute testMe(5,51,"Hello back to you!"), what will print? def testMe (p,q,r): if q > 50: print r value = 10 for i in range (1,p): print "Hello" value = value - 1 print value print r
Write a function called erasePart to set all the samples in the 2nd second of thisisatest.wav to 0’s—essentially, making the 2nd second go silent.
Write a function that interleaves two sounds. It starts with 2 seconds of the first sound and then 2 seconds of the second sound. Then it continues with the next 2 seconds of the first sound and the next 2 seconds of the second sound and so on until both sounds have been fully copied to the target
Write a function that splices together words and music.
Search the Web for songs that have hidden messages that you can hear when you reverse the sound.
Write a function to add 1 second of silence to the beginning of a sound. It should take the sound as input, create the newempty target sound, then copy the original sound starting after the first second in the target.
Compose a sentence that no one ever said by combining words from other sounds into a grammatically correct newsound. Write a function named audio- Sentence to generate a sentence out of individual words. Use at least three words in your sentence.You can use the words in the mediasource folder from
Make an audio collage. Make it at least 5 seconds long, and include at least two different sounds (i.e., they come from different files). Make a copy of one of those different sounds and modify it using any of the techniques described in this chapter (i.e., mirroring, splicing, volume
Try using a stopwatch to time the execution of the programs in this chapter. Time from hitting return on the command until the next prompt appears. What is the relationship between execution time and the length of the sound? Is it a linear relationship (i.e., longer sounds take longer to process
We think that if we’re going to say “We the united people” in the splice (Program 104), “united” should be really emphasized—really loud. Change the program so that the word “united” is maximally loud (normalized) in the phrase “united people.”Data from Program 104 # Splicing #
The general functions like Program 108 (page 248) are the kind where the index array notation is really useful. Write reverse, copy, and clip using index array notation.Data from Program 108 def reverse(source): target = makeEmptySound (getLength(source)) getlength (source)-1 for targetIndex in
What happens if you take out the bit of silence added in to the target sound in the splicing example (Program 104 (page 242))? Try it? Can you hear any difference?Data from Program 104 # Splicing # Using the preamble sound, # make "We the united people" def splicePreamble(): source = makeSound
Try rewriting Program 100 so that you have a linear increase in volume to halfway through the sound, then linearly decrease the volume down to zero in the second half.Data from Program 100 def increaseAndDecrease (sound) : for sampleIndex in range (0,getLength (sound)/2): value = getSampleValueAt
Rewrite Program 100 so that you normalize the first second of a sound, then slowly decrease the sound in steps of 1/5 for each following second. (How many samples are in a second? getSamplingRate is the number of samples per second for the given sound.)Data from Program 100 def increaseAndDecrease
Rewrite Program 100 (page 236) so that two input values are provided to the function: the sound and a percentage of how far into the sound to go before changing from increasing to decreasing the volume.Data from Program 100 def increaseAndDecrease (sound) : for sampleIndex in range (0,getLength
Try sprinkling in some specific values into your sounds. What happens if you set the value of a few thousand samples in the middle of a sound to 32,767? Or a few thousand to −32,768? Or set the few thousand sample to a bunch of zeroes? What happens to the sound in each of these
What happens if you increase a volume too far? Explore this by creating a sound object, then increasing the volume once, and again, and again. Does it always keep getting louder? Or does something else happen? Can you explain why?
In Section 7.3.2, wewalked through how Program 93 worked. Drawthe pictures to show how Program 94 (page 225) works in the same way.Data from Program 93Data from Program 94 def increaseVolume (sound): for sample in getSamples(sound): getSampleValue(sample) * 2) value setSampleValue(sample,value
Rewrite increase volume (Program 93) so that it takes two inputs: a sound to increase in volume and a multiplier. Use the multiplier as how much to increase the amplitude of the sound samples. Can we use the same function to both increase and decrease the volume? Demonstrate commands that you would
Rewrite increase volume (Program 93) so that it takes two inputs: the sound to increase in volume and a filename where the newly louder sound should be stored. Then increase the volume and write the sound out to the name file.You might also try rewriting it so that it takes an input filename
Get a sound. Run increaseVolume on the sound, and then onlyMaximize on the same sound. Get an original copy of the sound. Now, run fauxIncrease-Volume on the new copy, and then onlyMaximize on the output of faux- IncreaseVolume. The sounds will sound different. If the sound had words in it, the
Sometimes people think that the way to increase volume is to add a value (like 1000) to every sample. Write the function fauxIncreaseVolume(sound, increment) to add an input value increment to every sample in an input sound. Try your function with an increment of 1000. Can you hear a difference in
Write a function to set values that are greater than 0 to the maximum positive value (32,767) in a sound, but leave all the negative values the same. Can you still understand any words in the sound?
Write a function to count the number of times the value of a sample is 0 and print out the total.
Write a function to find the smallest value in a sound and print it out.
Write a function to set all the negative values of a sound to zero. Can you still understand any words in the sound?
Write a function to increase the volume for all the positive values and decrease the volume for all the negative values. Can you still understand any words in the sound?
The increase volume recipe (Program 93 (page 221)) takes a sound as input. Write a function increaseVolumeNamed that takes a filename as input, then plays the louder sound.Data from Program 93 def increaseVolume (sound): for sample in getSamples(sound): getSampleValue(sample) * 2) value
Try out a variety of WAV files as instruments, using the piano keyboard in the MediaTools application sound editor. What kinds of recordings work best as instruments?
Get a couple of different instruments and play the same note on them in the MediaTools application’s sound editor with the sonogram view open. Are all “C’s” made equal? Do they have the same tones and overtones? Using the MediaTools visualization, can you see the differences between the
Open up a Sonogram view in the MediaTools application or a similar sound visualization tool say some vowel sounds. Is there a distinctive pattern? Do “oh’s” always sound the same? Do “ah’s”? Does it matter whether you switch people: Are the patterns the same?
Write the number −9 in two’s complement. Write the number 4 in two’s complement. Write the number −27 in two’s complement.
Define the following terms.1. Clipping2. Normalize3. Amplitude4. Frequency5. Rarefactions
One of the four functions below generated this picture.Which one is it?A.B.C.D. def flip1(picture): allpixels = getPixels(picture) In = len(allpixels)-1 address = In for index in range (0,1n/2): allpixels[index] getColor (mypixel) allpixels [address] setColor (newpixel, color) mypixel color =
One of the four functions below generated this picture.Which one is it?A.B.C.D. def newpic1(inpic): getwidth(inpic) getHeight(inpic) outpic = W = h makeEmptyPicture (w,h) outX = w-1 for inx in range (0,w/2): outY h-1 for inY in range (0,h/2): inpixel getPixelAt(inpic, inX,inY) getColor(inpixel)
Think about how the grayscale algorithm works. Basically, if you know the luminance of anything visual (e.g., a small image, a letter), you can replace a pixel with that visual element in a similar way to create a collage image. Try implementing this. You’ll need 256 visual elements of increasing
Write a function named makeCollage to create a collage of the same image at least four times fit onto the 7in.x95in.jpg blank JPEG. (You are welcome to add additional images.) One of those four copies can be the original picture. The other three should be modified forms. You can scale, crop, or
Using nested loops, write a function that reduces red in the top third of a picture and clears blue in the bottom third.
Write a function to mirror the input picture’s leftmost 20 pixels to pixels 20 to 40.
Write a general function to copy a triangular area from one picture to another.
Modify any of the functions from the last chapter to use a nested loop. Check the result to make sure it still does the same thing.
Write a general scaleDown function that takes in any picture and creates and returns a new picture half as big using makeEmptyPicture(width,height).
Write a function to flip a picture over so that if someone was looking right, they end up looking left.
Write a function that will scale down just a part of the picture. Make someone’s head look smaller.
Write a function that will scale up just part of the picture. Try making someone’s nose longer.
What do you get from copyHorseLarger you skipped a pixel between every other pixel?
The function copyHorseLarger didn’t really work when we copied the pixel twice. What if we copied it four times? Does that look better?
Write a function to mirror along the diagonal from (0, height) to (width, 0).
Write a function to mirror along the diagonal from (0, 0) to (width, height).
We’ve seen that if you increment the source picture index by 2 while incrementing the target picture index by 1 for each copied pixel, you end up with the source being scaled down onto the target. What happens if you increment the target picture index by 2 as well? What happens if you increment
If you call the function above by typing: newFunction("I", "you", "walrus"), what will print? def newFunction (a, b, c): print a list1 = range (0,4) value = 0 for x in 1istl: print b value value +1 print c print value
Which of the programs below takes a picture and removes all the blue fromevery pixel that already has a blue value of more than 100?1. A only2. D only3. B and C4. C and D5. None6. AllWhat do the other ones do?A.B.C.D. def blueOneHundred (picture): for x in range (0,100): for y in range (0,100):
Draw a rainbow—use what you know about colors, pixels, and drawing operations to draw a rainbow. Is this easier to do with our drawing functions or by manipulating individual pixels? Why?
Now use your simple face function in a loop to draw a whole crowd of people.
Now use your house function to draw a town with dozens of houses at different sizes. You’ll probably want to modify your house function to draw at an input coordinate, then change the coordinate where each house is drawn.
Draw a house on the beach where we put the mysterious box previously.
What is a vector-based image? How does it differ from a bitmapped image? When is it better to use a vector-based image?
Draw diagonal lines on a picture from top right to bottom left using addLine.
Draw diagonal lines on a picture from top left to bottom right using addLine.
Draw horizontal and vertical lines on a picture where the gap between the lines increases linearly. Start at 10, then 12, then 14.
Draw horizontal and vertical lines on a picture with 10 pixels between the lines.
Using the drawing tools presented here, draw a house—just go for the simple child’s house with one door, two windows, walls, and a roof.
Using the drawing functions, draw a bull’s eye.
Create a comic strip by putting three to four pictures next to each other horizontally and adding text.
Create a movie poster by drawing text on a picture.
The black in the function copyHorseFaceSmallBlack doesn’t look great on that horse.Would red look better? Try it.
Rewrite the Jenny’s eyes function to double Jenny’s eyes, making them appear twice.
Write a function to pull out just Jenny’s eyes, rather than remove the red in them, and paste them into a canvas.
Get some green posterboard and take a picture of a friend in front of it. Now use chromakey to put her or him in the jungle. Or better yet, in Paris.
Why do moviemakers use a green or blue screen for special effects instead of a red screen?
Rewrite Program 52 (page 124) to use an if with an else.Data from Program 52 def posterize(picture): #loop through the pixels for p in getPixels (picture): #get the RGB values red = getRed (p) green = getGreen (p) blue = getBlue (p) %3D %3! #check and set red values if(red < 64): setRed (p, 31)
Write a function to blend two pictures: 25% of one picture blended with 75% of another.
Write a function to interleave two pictures taken as input. Take the first 20 pixels from the first picture and then 20 pixels from the second picture and then the next 20 pixels from the first picture and then the next 20 pixels from the second picture and so on till all the pixels have been used.
Write a function to blend two pictures, starting with the top third of the first picture and then blend the two together in the middle third and then show the last third of the second picture. This works best if the two pictures are the same size.
Try doing background subtraction in a range.Take the “dog-bg.jpg” and “nodogbg. jpg” pictures as input, with an upper left-hand corner x and y, and lower right-hand corner x and y. Do background subtraction just around the dog in the chair, leaving the leaves and the house alone.
Try doing chromakey in a range. The picture “statue-tower.jpg” has a blue, but not blue enough background to work with chromakeyBlue. However, if you change the rule to getRed(px) + getGreen(px) < getBlue(px)+100, it works great for the sky—but messes up near the ground.• Change
Write a program checkLuminance that will input red, green, and blue values, and compute the luminance using the weighted average (as below). But then print out a warning to the user based on the computed luminance:• If the luminance is less than 10, “That’s going to be awfully dark.”• If
Start with a picture of someone you knowand make some specific color changes to it:• Turn the teeth purple.• Turn the eyes red.• Turn the hair orange.Of course, if your friend’s teeth are already purple, or eyes red, or hair orange, choose a different target color.
What will be printed for this function if you executed each of these:(a) TestMe (1, 2, 3)(b) TestMe (3, 2, 1)(c) TestMe (5, 75, 20) def testMe (p,q, r): if q > 50: print r value = 10 for i in range (0,p): print "Hello" value = value - 1 %3D print value print r
Rewrite Program 52 (page 124) using this helper function to make it much shorter.Data from Program 52 def pickPosterizeValue(current): if (current < 64): return 31 if (current > 63 and current < 128): return 95 if (current > 127 and current < 192): return 159 if (current > 191 and current < 256):
Write a function that treats horizontal thirds of the picture differently. Make the top third of an input picture brighter, then the middle third decrease blue and green by 30%, then the bottom third should be made negative.
Write a function to make lighter the left side of a picture, and turn the right side into a grayscale.
Showing 200 - 300
of 409
1
2
3
4
5
Step by Step Answers