Python Part 2: Guess the song For the second part of this project, you will write code
Fantastic news! We've Found the answer you've been seeking!
Question:
Python
Transcribed Image Text:
Part 2: Guess the song For the second part of this project, you will write code that implements a song-guessing game. Part 2.1: Pick a random song After creating a list of songs (part 1), your code should pick a song at random from that list. You should use the random.choice () method for this (be sure to import the random module). Part 2.2: Play a song preview After picking a random song (2.1), your code should play an audio preview of the song. To do this, you must import a few features from the IPython.display module: from IPython.display import display, Audio, clear_output After you do this, if you are given a URL for an audio file (suppose it is in the variable audio_url ), you can play it with: display (Audio (audio_url, autoplay=True)) For example, you can try this with the audio url: 'https://audio-ssl.itunes.apple.com/itunes-assets/Music7/v4/cd/a8/4c/cda84ca4-3ef1-d2b5-6f88-3640e5db33fc/mzaf_1355556193908011287.plus.aac.p.m4a' Note: If your audio does not play, try adding the following code snippet: import mimetypes mimetypes.init() mimetypes.add_type('audio/mp4', .m4a') Part 2.3: Print a "blanked out" version of the song: After picking a random song (2.1) and playing a song preview (2.2), your code should Replace every alphanumeric character (meaning a-z, 0-9) in the track name with an underscore ('_'). For example, a song titled "(I Can't Get No) Satisfaction" should print out: "(_ ___'_ (I Can't Get No) Satisfaction (___ You can check if a character is alphanumeric with the .isalnum() method: 'a'.isalnum() is True. '#'.isalnum() is False. Part 2.4: Allow the user to guess the track name (or pass) After your code picks a random song (2.1), plays the song preview (2.2), and prints a "blanked out" version of the song (2.3), your code should repeatedly ask the user to guess the song. Every time, your code should: Ask the user to enter a guess (using input()) If the user guessed the correct track name, print "You got it!". If the user guessed incorrectly, print "It's not '<what the user entered>'" If the user enters 'pass' then your code should display the correct answer ("The song was '<track name>'") and stop asking for guesses. This part should not be case sensitive; if the correct answer is 'Thriller' and the user guesses 'THRILLER', this should count as being correct. You can use Python strings.upper() method to achieve this. Part 2.5: Indefinite rounds Finally, your code should repeat parts 2.1--2.4 indefinitely (until the user types 'exit' ). Note that this means you will need to have nested while loops (one for 2.4 and one for this part). One way to achieve this would be to put the code for part 2.4 into a separate function. Every round, your code should: 1. Print == ROUND <#> ==', replacing <#> with the round number ( 1, 2, 3,...) 2. Pick a random song (as implemented for 2.1) 3. Play a preview of the song (as implemented for 2.2) 4. Print a "blanked out" version of the song (as ipmlemented for 2.3) 5. Allow the user to guess the song with an indefinite number of chances (as implemented for 2.4), with the following modification: If the user types 'exit', your code should display the correct answer, wait 3 seconds, and clear the output (see #6 for how to do this) The user should still be able to enter 'skip' to skip to the next round. The difference between 'pass' and 'exit' is that 'pass' should move on to the next round. 'exit' should exit the guessing game entirely. 6. After the user guesses correctly (or passes), your code should: Display the correct track name (if the user passed) . . Wait 3 seconds (you can do this by importing the time module and calling time.sleep (3) Call clear_output() (imported from IPython.display earlier) to clean up the output. 7. Increment the round and start up again at step 1 Part 2: Guess the song For the second part of this project, you will write code that implements a song-guessing game. Part 2.1: Pick a random song After creating a list of songs (part 1), your code should pick a song at random from that list. You should use the random.choice () method for this (be sure to import the random module). Part 2.2: Play a song preview After picking a random song (2.1), your code should play an audio preview of the song. To do this, you must import a few features from the IPython.display module: from IPython.display import display, Audio, clear_output After you do this, if you are given a URL for an audio file (suppose it is in the variable audio_url ), you can play it with: display (Audio (audio_url, autoplay=True)) For example, you can try this with the audio url: 'https://audio-ssl.itunes.apple.com/itunes-assets/Music7/v4/cd/a8/4c/cda84ca4-3ef1-d2b5-6f88-3640e5db33fc/mzaf_1355556193908011287.plus.aac.p.m4a' Note: If your audio does not play, try adding the following code snippet: import mimetypes mimetypes.init() mimetypes.add_type('audio/mp4', .m4a') Part 2.3: Print a "blanked out" version of the song: After picking a random song (2.1) and playing a song preview (2.2), your code should Replace every alphanumeric character (meaning a-z, 0-9) in the track name with an underscore ('_'). For example, a song titled "(I Can't Get No) Satisfaction" should print out: "(_ ___'_ (I Can't Get No) Satisfaction (___ You can check if a character is alphanumeric with the .isalnum() method: 'a'.isalnum() is True. '#'.isalnum() is False. Part 2.4: Allow the user to guess the track name (or pass) After your code picks a random song (2.1), plays the song preview (2.2), and prints a "blanked out" version of the song (2.3), your code should repeatedly ask the user to guess the song. Every time, your code should: Ask the user to enter a guess (using input()) If the user guessed the correct track name, print "You got it!". If the user guessed incorrectly, print "It's not '<what the user entered>'" If the user enters 'pass' then your code should display the correct answer ("The song was '<track name>'") and stop asking for guesses. This part should not be case sensitive; if the correct answer is 'Thriller' and the user guesses 'THRILLER', this should count as being correct. You can use Python strings.upper() method to achieve this. Part 2.5: Indefinite rounds Finally, your code should repeat parts 2.1--2.4 indefinitely (until the user types 'exit' ). Note that this means you will need to have nested while loops (one for 2.4 and one for this part). One way to achieve this would be to put the code for part 2.4 into a separate function. Every round, your code should: 1. Print == ROUND <#> ==', replacing <#> with the round number ( 1, 2, 3,...) 2. Pick a random song (as implemented for 2.1) 3. Play a preview of the song (as implemented for 2.2) 4. Print a "blanked out" version of the song (as ipmlemented for 2.3) 5. Allow the user to guess the song with an indefinite number of chances (as implemented for 2.4), with the following modification: If the user types 'exit', your code should display the correct answer, wait 3 seconds, and clear the output (see #6 for how to do this) The user should still be able to enter 'skip' to skip to the next round. The difference between 'pass' and 'exit' is that 'pass' should move on to the next round. 'exit' should exit the guessing game entirely. 6. After the user guesses correctly (or passes), your code should: Display the correct track name (if the user passed) . . Wait 3 seconds (you can do this by importing the time module and calling time.sleep (3) Call clear_output() (imported from IPython.display earlier) to clean up the output. 7. Increment the round and start up again at step 1
Expert Answer:
Answer rating: 100% (QA)
e implementation for the songguessing game python Copy code import random from IPythondisplay import ... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
: Write code in the next cell to do the following: 1. Asks the user for their first, middle, and last names and stores each in a new variable. 2. Computes the length of the name not including spaces...
-
Write Python code to implement the City Council management system. The program should do the following: Deliverables for this assignment are: 1. For the management system allocated to you, develop...
-
For this problem you must use Python semaphore class. Your implementation for this problem must only use the semaphore methods to control the concurrency of your solution (IE. acquire and release)....
-
What is true of a balance sheet? Question 6Answer a. The equation used in a balance sheet is Assets = Liabilities + Net Assets b. The equation used in a balance sheet is Assets = Net Assets =...
-
We know that the geometric average (time-weighted return) on a risky investment is always lower than the corresponding arithmetic average. Can the IRR (the dollar-weighted return) similarly be ranked...
-
Would it be valuable for Herms to gather competitive intelligence? Why or why not?
-
How to obtain an extension of time and continuances?
-
Mira Services Co. offers its services to individuals desiring to improve their personal images. After the accounts have been adjusted at October 31, the end of the fiscal year, the following balances...
-
A growing concern for systems is the ability of the system to prevent a cyber attack, reduce the vulnerability to the system if attacked, and provide resiliency to complete the mission despite an...
-
The chief financial officer for Eagles Beach Wear and Gift Shop is planning for the companys cash flows for the next six months. The following table summarizes the expected accounts receivables and...
-
Falcon Corporation ended Its first year of operations with a taxable income of s250.oo.At the time of Falcon's formation incurred s50,000 in organizational expenses. In calculating Its taxable income...
-
Discuss the potential security risks associated with storing and processing sensitive data within a GBMS .?
-
Suppose you were long in a T-bond futures contract at 94-16. At the futures expiration for a delivered T- bond, if the bond's conversion factor was 1.1 and the accrued interests on the deliverable...
-
The Platter Valley factory of Bybee Industries manufactures field boots. The cost of each boot includes direct materials, direct labor, and manufacturing ( factory ) overhead. The firm traces all...
-
Hunter, Inc. analyzed its accounts receivable balances at December 3 1 , and arrived at the aged balances listed below, along with the percentage that is estimated to be uncollectible: % Considered...
-
12. A 50.0 mL sample of saltwater that is 3.0% m/v is diluted to 950 mL. What is its final mass/volume percent?
-
Arrange the highlighted bonds in the table below in decreasing order of polarity. That is, pick 1 for the most polar bond, pick 2 for the next most polar bond, and so on. bond H H-C- H H H H H H C...
-
Refer to the information from Exercise 22-19. Use the information to determine the (1) Weighted average contribution margin , (2) Break-even point in units, and (3) Number of units of each product...
-
Lisa Sizemore, a taxpayer in the 10-15 percent tax bracket, purchased stock as an investment on July 11, 2011. She sold the stock on July 9, 2012, 2 days before qualifying for the long-term holding...
-
Ken paid the following amounts for interest during 2012: Qualified interest on home mortgage...........................................$4,700 Auto loan...
-
Dr. George E. Beeper is a single taxpayer. He lives at 45 Mountain View Dr., Apt. 321, Spokane, WA 99210. Dr. Beeper's Social Security number is 775-88-9531. Dr. Beeper works for the Pine Medical...
-
Think of all the ways a binary flash distillation problem can be specified. For example, we have usually specified F, z, Tdrum, Pdrum in addition to T and p. If T and p are constant, what other...
-
Figure 2-4 is at a pressure of 1.0 kg/cm 2 (actually kgf/cm 2 ), which was formerly a fairly common pressure unit. What is the pressure in bar and in atm? 100 400 O 05 100
-
An existing flash drum is available. The vertical drum has a demister and is 4 ft in diameter and 12 ft tall. The feed is 30 mol% methanol and 70.0 mol% water. A vapor product that is 58 mol%...
Study smarter with the SolutionInn App