Question
using python 3: please only serious programer. i have a code below that need good indentation and fix if needed. Thanks and i always rate
using python 3: please only serious programer. i have a code below that need good indentation and fix if needed. Thanks and i always rate my answer.
The set of musical notes is A, A#/Bb, B, C, C#/Db, D, D#/Eb, E, F, F#/Gb, G, G#/Ab. All notes start with a letter and may be followed by either # (sharp) or b (flat). A# and Bb are two names for the same note. The distance between two consecutive notes is a half-step. A sequence of 12 half-steps is called an octave. As you can see in the picture, if you move a full octave, you will return to the same note but at a higher or lower pitch.
A chromatic scale includes all the notes in an octave, either with sharps or flats but not both. So A A# B C C# D D# E F F# G G# is a sharp chromatic scale and A Bb B C Db D Eb E F Gb G Ab is a flat chromatic scale.
A piece of music is written in a specific key (a set of notes in a scale). However, a musician may wish to transpose the piece to a different key by uniformly raising or lowering its notes. This is done to either change its pitch or to convert to a set of notes that is more easily played. As an example, the sequence C D E could be transposed down 3 half-steps to become A B C# or A B Db. Similarly, it could be transposed up by 1 half-step to become C# D# F or Db Eb F.
A chord is a group of notes played together. Its lowest note is called its root. The name of a chord is derived from its root note, for example, F#.
The purpose of this assignment is to write a program that will take a set of chords, allow the user to indicate how many half-steps to transpose and display the resulting chords.
Divide the program into three functions:
main
Declare a string that that represents a set of chords (just the roots at this point)
Get input for the number of half-steps
Display the the transposed chords
a function with one parameter, a string of chords.
Return a list of chords from the given string. (In this assignment, the function is only one or two lines, but will be expanded in the future.)
a transpose function with two parameters, a string of chords, and the number of half-steps.
Determine whether the original chords use either a sharp or flat scale and make the corresponding chromatic scale.
Construct the set of transposed chords.
Return a string of transposed chords.
Use string and list methods and operations in your solution.
Examples: transposing "Eb D C F Bb G" 1 half-step down (-1) should produce the string, "D Db B E A Gb"; transposing "D# D C F A# G" 11 half-steps up (+11) should produce the string, "D C# B E A F#"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
HERE IS MY CODE
import sys # returns list of chords from the given string def get_list_of_chords(string_of_chords): return string_of_chords.strip(' ').split(' ')
# transposes the string of chords to given no_of_half_steps def transpose(string_of_chords, no_of_half_steps): # validations & determination of chords type uses_sharp_scale,uses_flat_scale = False, False if '#' in string_of_chords and 'b' not in string_of_chords: uses_sharp_scale = True print('Original chords use sharp scale.') elif '#' not in string_of_chords and 'b' in string_of_chords: uses_flat_scale = True print('Original chords use flat scale.') elif '#' not in string_of_chords and 'b' not in string_of_chords: print('Invalid string of chords, Original chords neither use flat scale nor use sharp scale, exiting...') sys.exit() else: print('Invalid string of chords, cant use flat and sharp scales in same string, exiting...') sys.exit() sharp_scaled, flat_scaled = '', '' transposed_chords = [sharp_scaled, flat_scaled] list_of_chords = get_list_of_chords(string_of_chords) # transposing chords by no_of_half_steps for chord in list_of_chords: for i in range(len(set_of_musical_notes)): if set_of_musical_notes[i][0] == chord or set_of_musical_notes[i][-1] == chord: if uses_sharp_scale: sharp_scaled += ' '+set_of_musical_notes[(i+no_of_half_steps)%len(set_of_musical_notes)][0] if uses_flat_scale: flat_scaled += ' '+set_of_musical_notes[(i+no_of_half_steps)%len(set_of_musical_notes)][-1] #if uses_flat_scale: #return flat_scaled.strip(' ') #else: #return sharp_scaled.strip(' ') # main function def main(): # Declaring string of chords string_of_chords = 'Eb D C F Bb G' # this can be edited
# input number of half steps no_of_half_steps = int(input('Input number of half steps:'))
# Displays the transposed chords transposed_chords = transpose(string_of_chords, no_of_half_steps) print('Transposing chords', string_of_chords, 'no_of_half_steps:', no_of_half_steps, 'is', transposed_chords)
# initializing set_of_musical_notes set_of_musical_notes = 'A, A#/Bb, B, C, C#/Db, D, D#/Eb, E, F, F#/Gb, G, G#/Ab'.split(', ') set_of_musical_notes = [item.split('/') for item in set_of_musical_notes]
if __name__ == "main":
main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started