dimanche 24 janvier 2021

Require input after each line during while loop

During a while loop - how do i force input after each line.

Program is meant to help people to start writing a song. So program offers a randomly-selected key. The user has the opportunity to request another key. I want the user to continue to have this opportunity until they are given a key they would like to use.

At the moment it runs an infinite loop - with no opportunity for user input

import random
majorkeys = ['A major', 'Bb major', 'B major', 'C major', 'Db major', 'D major', 'Eb major', 'E major', 'F major',
             'Gb major', 'G major', 'Ab major']
minorkeys = ['A minor', 'Bb minor', 'B minor', 'C minor', 'Db minor', 'D minor', 'Eb minor', 'E minor', 'F minor',
             'Gb minor', 'G minor', 'Ab minor']
allkeys = ['A major', 'Bb major', 'B major', 'C major', 'Db major', 'D major', 'Eb major', 'E major', 'F major',
           'Gb major', 'G major', 'Ab major', 'A minor', 'Bb minor', 'B minor', 'C minor', 'Db minor', 'D minor',
           'Eb minor', 'E minor', 'F minor','Gb minor', 'G minor', 'Ab minor']

#Lydia - in reference to Lydian Mode.
print("""
Hey there, my name is Lydia,
I'm here to help you start a song!
    """)

knownkey = (input("Do you know what key you would like to start with? "))

if knownkey == "no":
    print("\nLet me help you get this song off the ground! Try start with:")
    print(random.choice(allkeys))
else:
    print("That's a great starting point! Nice Work!")

confirmkey = (input("Are you happy to continue with this key? "))

while (confirmkey) == "no":
    print("No worries! Lets do:")
    print(random.choice(allkeys)+" instead!")
else:
    print("Awesome")

Aucun commentaire:

Enregistrer un commentaire