Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using python 3. I always grade my answer. below you will find assignment 6 Instructions Edit your program from assignment 6 Write a new function

using python 3. I always grade my answer. below you will find assignment 6

Instructions

Edit your program from assignment 6

Write a new function that returns a transposing dictionary

It has two parameters: whether the original chords use sharps or flats, and the number of half-steps

Build the dictionary using each note as a key and the note offset by the number of half-steps as the associated value

For example, if the sharps were used, the notes are A ,A#, B, C, C#, etc. And if the number of half-steps is 10, the dictionary would be {A:G, A#:G#, B:A, C:A#, C#:B, etc}.

Edit your function that transposes

Remove any code that produces a scale of notes (since this is now performed in the dictionary function)

Before the loop where you transpose, call your function that makes the transposing dictionary

Inside of the loop where you transpose, use the dictionary to determine the transposed root

After you have completed the previous steps, edit the main function:

Prompt the user for whether the result should contain sharps or flats

Pass this as a parameter when you call your transpose function

Edit both your transpose function and your dictionary function:

Add a third parameter for whether the result should contain sharps or flats

Edit the dictionary function

The dictionary keys will remain the same as previously.

However, the dictionary values will depend on whether the new parameter for the function indicates to use sharps or flats in the result. If sharp result, the dictionary values will include A, A#, B, C, C#, D, D#, E, F, F#, G, G#; if flat result, the dictionary values will include A, Bb, B, C, Db, D, Eb, E, F, Gb, G, Ab

Examples:

Transposing "Eb D C F Bb G" -1 half-steps with a flat result should produce the string "D Db B E A Gb". But with a sharp result it should be "D C# B E A F#".

Transposing "D# D C F A# G" +11 half-steps with a sharp result should produce the string "D C# B E A F#". But with a flat result it should be "D Db B E A Gb".

Transposing "Eb F7 Bb7 Eb Gm Ab Gm Fm Eb" -1 half steps to sharps, the final result is "D E7 A7 D F#m G F#m Em D".

ASSIGNMENT 6

def main(): =====chords = 'Eb D C F Bb G' =====halfsteps = int(input('enter half steps:')) =====print(transpose(chords, halfsteps)) def makechordlist(s):

===chords = s.split()

===for(index,c)in enumerate(chords):

=====if# in c or b in c:

=======boundary = 2

=====else:

=======boundary= 1

=====chords[idex] = (c[:boundary], c[boundary:]) =====return chords def transpose(chrdstr, halfsteps): ====if '#' in chrdstr: ======scale = 'A A# B C# D D# E F# G G# '.split() ====else: ======scale = 'A Bb B C Db D Eb E F Gb G Ab'.split()

====chrdlist = makechordlist(chrdstr)

====tchords = []

====for(root,var) in chrdlist:

======i = (scale.index(root)+ halfsteps)%12 ======tchords.append(scale[i]) ====return ' '.join(tchords) if __name__=='__main__': main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions

Question

13-6 How will MIS help my career?

Answered: 1 week ago