In PythonRestrictions • There is exactly one import statement allowed in this project: import random O You are not allowed to import anything else. O You 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: o 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 files_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.song” 90 using the song on the left, the changed song is on the right change_notes(‘test.song’, {’02’:’E3′}, 5) 440 A4, Quarter A#2, Quarter B5, Quarter C2, Quarter C#2, Quarter D3, Quarter D#2, Quarter E6, Quarter F7, Quarter F#1, Quarter G5, Quarter G#6, Quarter “test_changed.song” 90 440 D5, Quarter D#3, Quarter E6, Quarter E3, Quarter F#2, Quarter G3, Quarter G#2, Quarter A6, Quarter A#7, Quarter B1, Quarter C6, Quarter C#7, Quarter Show transcribed image text Restrictions • There is exactly one import statement allowed in this project: import random O You are not allowed to import anything else. O You 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: o 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 files_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.song” 90 using the song on the left, the changed song is on the right change_notes(‘test.song’, {’02’:’E3′}, 5) 440 A4, Quarter A#2, Quarter B5, Quarter C2, Quarter C#2, Quarter D3, Quarter D#2, Quarter E6, Quarter F7, Quarter F#1, Quarter G5, Quarter G#6, Quarter “test_changed.song” 90 440 D5, Quarter D#3, Quarter E6, Quarter E3, Quarter F#2, Quarter G3, Quarter G#2, Quarter A6, Quarter A#7, Quarter B1, Quarter C6, Quarter C#7, Quarter
Expert Answer
Answer to Restrictions • There is exactly one import statement allowed in this project: import random O You are not allowed to i…