All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
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
Ask a Question
Search
Search
Sign In
Register
study help
computer science
introduction to computing and programming in pytho
Questions and Answers of
Introduction to Computing and Programming in Pytho
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
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
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
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
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
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
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
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
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
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
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”
The function printNow is not the only way to present information to the user during the running of a program. We might also use the function showInformation which takes a string as input, then
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
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
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
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
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
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
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”
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
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 #
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
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
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
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
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
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):
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
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
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
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
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
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
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
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):
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
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
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
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.
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
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
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
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
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
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
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
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)
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
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
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
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 <
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
Showing 200 - 300
of 410
1
2
3
4
5