(Solved) : Write Following Function Python Please Document Code Understand Q42784661 . . .

Write the following function in python and please document thecode so then i can understand it

Background Dictionaries give an enriched way to store values by more than just sequential indexes (as lists give us); we iden

A standard piano has 88 keys that just repeat this pattern of notes over and over again. As you travel to the right the notes

Note Types There are few different speeds at which a note can be played in a piece of music. We generally think of this in te

—————————————————————————————————————————–

change_notes(filename, changes, shift) Description: Changes the notes of the song given by the filename based on the paramete

Background Dictionaries give an enriched way to store values by more than just sequential indexes (as lists give us); we identify key-value pairs, and treat keys like indexes of various other types. The only restriction on keys is that they are “hashable”, which we can approximate by thinking that they are “immutable all the way down” Though unordered, dictionaries help us simplify many tasks by keeping those key-value associations. Each key can only be paired with one value at a time in a dictionary When a file contains text, we can readily write programs to open the file and compute things based on the file’s contents. This also gives our programs far more longevity: we can store data and results for later, save user preferences, and all sorts of other useful things Scenario In this project you will get practice creating and manipulating dictionaries, and reading/writing files, by working with special “song” files that contain all the information needed to play a song on a piano (and subsequently on your computer.) Definitions There are 7 basic notes on a piano each given the letter A, B, C, D, E, F, or G. All of these notes are played by pressing one of the white keys. There are notes that exist in between some of the standard notes, which are referred to as “sharps.” They are played by pressing the black keys on a piano. One “octave” on the piano is the group of 12 notes from C to B, pictured below. Since there are sharp notes, we consider each of the keys that are next to each other as one ‘half-step’ apart. This means that C to C# is one half step, but C to D would be two half steps. Notice how there is no extra sharp note between E and F, or B and C. Both of these adjacent pairs of notes are still considered one half-step apart F C# G# A# D# 11 II c D E F G A B 1 A standard piano has 88 keys that just repeat this pattern of notes over and over again. As you travel to the right the notes get higher, and they get lower as your travel to the left. The notes that are in higher octaves sound higher pitched, and the lower octaves sound lower pitched. You will use a combination of the note’s letter and the octave it is played in to accurately describe an individual key on the piano. Octave 5 Octave 4 Octave 3 F# Gi Al CB D CB D C# Di FG Al FG A II 11 cD EF GA B CDEF GLAa BCDEFTAB in a song, this would be F#3 this is A4! this would be G5 Notice how the notes themselves are repeated several times. A standard piano has 7 full octaves (1 through 7), but the first key will actually start at A0, and the last key will be C8. Octaves 0 and 8 on the piano are therefore incomplete, they will only have the notes A0, A#O, BO, and C8. By pressing any of the keys on the piano, you are causing a small hammer to hit a string that will vibrate at a particular frequency. A note is octave 5 will have twice the frequency of the same note in octave 4, which is why the octave 5 note sounds higher pitched. You can compute the frequencies for each note by implementing the following formula: FT Fo X 2″/12 Fo is the frequency of base note, in other words the note that you are using to tune all of the other notes. It is standard to tune your piano so that the note A4 is exactly 440Hz, but the function you write to generate the frequencies of the notes will use any arbitrary starting frequency. n is the number of half steps you are away from the base note (A4): n>0 means you are on a note above the base note oAf#4 is one half step above A4, so n=1 oB4 is two half steps above A4, so n-2 C#5 is four half steps above A4, so n-4 oA5 is twelve half steps above A4, so n=12 n<o means you are on a note below the base note o G#4 is one half step below A4, so n = -1 o G4 is two half steps below A4, so n = -2 o A3 is twelve half steps below A4, so n-12 oF3 is sixteen half steps below A4, so n -16 Note Types There are few different speeds at which a note can be played in a piece of music. We generally think of this in terms of ‘beats rather than seconds or minutes. A song will describe its overall tempo in beats per minute (BPM), where a higher BPM means a faster song. When reading music, the notes are organized in “measures.” The composer of the song would tell you how many beats should be in one measure. We will assume that all music used in this project uses 4 beats per measure. This makes computing the speeds easier. We have five different note types in this project. The name of the note type indicates how much of one measure that note should occupy: “Quarter” notes take up a quarter of the measure, so for us that is exactly 1 beat “Half” notes take up half of the measure, that would mean they last for 2 beats in our songs “Whole” notes take up the entire measure, so they require 4 beats to play correctly “Eighth” notes take up an eighth of the measure, so that would be half of one beat “Sixteenth” notes take up a sixteenth of a measure, so that would be a quarter of one beat Song Files Files that contain songs in this project are denoted by the extension “.song”, and are organized like this: SongTempoInBPM BaseNoteFrequency NoteLetterAndOctave, NoteType NoteLetterAnd0ctave, NoteType The first line of the file is the song’s tempo expressed in beats per minute. The second line of the file is frequency of the base note used to tune the rest of the notes. The rest of the lines contain the notes in the order that they should be played for a particular song. They are comma separated, where the first item is the note’s letter on the piano and octave that is should be played in You can open up these files in any plain text editor, they use only ASCII characters. Restrictions There is exactly one import statement allowed in this project: import random oYou are not allowed to import anything else. oYou can only use randint () choice() and seed () from the random library You are not allowed to use classes, exceptions, the with statement, and list/dictionary comprehensions. From the built-in functions, you are allowed to use: o range), len ( ), sorted(), int (), sum(), list (), float(), str () From list methods, you are allowed to use: o append), insert (), copy(), remove), pop(), index From the dictionary methods, you are allowed to us: get( values (), keys(), items ( ), update( For the file/string methods, you are allowed to use: o open (), strip(), split(), join () o read), readline ( ), readlines(), write (), writelines () You may not make more than one pass of a file when reading it. Do not circumvent this rule by reading in the file as one entity (one string, a list, etc.), and then performing multiple passes on that. Questions on Piazza like “Can I use [thing not listed above]?” will not be answered by an instructor. change_notes(filename, changes, shift) Description: Changes the notes of the song given by the filename based on the parameters passed to the function. If a note appears as a key in the dictionary of changes, it should just be changed to the corresponding value. Otherwise, the note should be shifted up or down the piano by shift number of half steps on the piano. You should not change notes in the song that would be shifted past a valid key on the piano on the left or on the right. For example, C8 should remain C8 if the shift value was 4. The resulting song should be written to a file, given the name of the original file “_changed” added before the extension “.song” Parameters: filename (string) the name of the file containing the song to change, changes is a dictionary that maps notes to other notes, it won’t necessarily have every note in it, shift (integer) is how many half steps up or down the piano from the original note you should travel in order to find the replacement note in the changed file Return value: None (the changed song should be written to a new file) Example: “test_changed.song” “test.song” 90 90 440 440 using the song on the left, the cha song is on the right A4,Quarter A#2,Quarter B5,Quarter C2,Quarter C#2,Quarter D5,Quarter D#3,Quarter E6,Quarter E3,Quarter F#2,Quarter change_notes’test.song’, {‘C2′:’E3’}, 5) D3,Quarter D#2,Quarter E6,Quarter F7,Quarter F#1,Quarter G3,Quarter G#2,Quarter A6,Quarter A#7,Quarter B1,Quarter G5,Quarter C6,Quarter G#6,Quarter C#7,Quarter Show transcribed image text Background Dictionaries give an enriched way to store values by more than just sequential indexes (as lists give us); we identify key-value pairs, and treat keys like indexes of various other types. The only restriction on keys is that they are “hashable”, which we can approximate by thinking that they are “immutable all the way down” Though unordered, dictionaries help us simplify many tasks by keeping those key-value associations. Each key can only be paired with one value at a time in a dictionary When a file contains text, we can readily write programs to open the file and compute things based on the file’s contents. This also gives our programs far more longevity: we can store data and results for later, save user preferences, and all sorts of other useful things Scenario In this project you will get practice creating and manipulating dictionaries, and reading/writing files, by working with special “song” files that contain all the information needed to play a song on a piano (and subsequently on your computer.) Definitions There are 7 basic notes on a piano each given the letter A, B, C, D, E, F, or G. All of these notes are played by pressing one of the white keys. There are notes that exist in between some of the standard notes, which are referred to as “sharps.” They are played by pressing the black keys on a piano. One “octave” on the piano is the group of 12 notes from C to B, pictured below. Since there are sharp notes, we consider each of the keys that are next to each other as one ‘half-step’ apart. This means that C to C# is one half step, but C to D would be two half steps. Notice how there is no extra sharp note between E and F, or B and C. Both of these adjacent pairs of notes are still considered one half-step apart F C# G# A# D# 11 II c D E F G A B 1
A standard piano has 88 keys that just repeat this pattern of notes over and over again. As you travel to the right the notes get higher, and they get lower as your travel to the left. The notes that are in higher octaves sound higher pitched, and the lower octaves sound lower pitched. You will use a combination of the note’s letter and the octave it is played in to accurately describe an individual key on the piano. Octave 5 Octave 4 Octave 3 F# Gi Al CB D CB D C# Di FG Al FG A II 11 cD EF GA B CDEF GLAa BCDEFTAB in a song, this would be F#3 this is A4! this would be G5 Notice how the notes themselves are repeated several times. A standard piano has 7 full octaves (1 through 7), but the first key will actually start at A0, and the last key will be C8. Octaves 0 and 8 on the piano are therefore incomplete, they will only have the notes A0, A#O, BO, and C8. By pressing any of the keys on the piano, you are causing a small hammer to hit a string that will vibrate at a particular frequency. A note is octave 5 will have twice the frequency of the same note in octave 4, which is why the octave 5 note sounds higher pitched. You can compute the frequencies for each note by implementing the following formula: FT Fo X 2″/12 Fo is the frequency of base note, in other words the note that you are using to tune all of the other notes. It is standard to tune your piano so that the note A4 is exactly 440Hz, but the function you write to generate the frequencies of the notes will use any arbitrary starting frequency. n is the number of half steps you are away from the base note (A4): n>0 means you are on a note above the base note oAf#4 is one half step above A4, so n=1 oB4 is two half steps above A4, so n-2 C#5 is four half steps above A4, so n-4 oA5 is twelve half steps above A4, so n=12 n

Expert Answer


Answer to Write the following function in python and please document the code so then i can understand it ————————…

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us

× How can I help you?