Could you help with a simple code? Python | Sololearn: Learn to code for FREE!

+2

Could you help with a simple code? Python

I’m trying to use a sequence which starts [6,2,4,4,4] to effect a a list of musical notes. Let’s say we take [“a”,”a#”,”b”,”c”,”c#”,”d”,”d#”,”e”,”e#”,”f”,”f#”,”g”,”g#”] How could I write some code in python to use the first number of the sequence [6] to go from [“a”] to [“d#”] and then the second number [2] to go from [“d#”] to [“e#”]? I have a list of 63 numbers I want to do this with so code would be helpful. I’m new to python but I’m sure it’s a simple code, maybe a for loop? Thanks Paul.

4/7/2019 6:44:22 PM

Paul

3 Answers

New Answer

+4

If I were to approach this, I would definitely use a for loop to go through every number in the list. In the loop, what you could do is have a single variable (maybe called index) which is what's going to decide the note specified by that number. All you would need to do is add the index by that number (with index starting at a value of 0), and return the value of the element at that index within the list of notes. Something like: index = 0 for x in numbers: index += x print(notes[index]) # This is simplified, but should give the idea of what I would do To move back, all you would need to do is set the number to be negative so that the index moves back instead of forward. (Also, E# is the same note as F, so I would recommend removing that haha)

+3

https://code.sololearn.com/cCpegX1akOr0/?ref=app

+2

thankyou you’re both geniuises, if youre wondering im trying to apply the changes in the iching to musical notes, just to see if the pattern could actually be music of some sort, thankyou! haha didnt notice the E# and F haha thankyou!