Reputation: 11
So I am trying to make a program where the user can enter commands to get to where they are going (start another program, etc..) but when they enter a command they can get to the end of that (section) and the program stops running
command = input('Please enter a command or enter help for a list of commands:')
if command in ['help', 'Help', 'HELP', '?']:
print("\t music \t Listen to music (XXXX songs)")
print("\t")
print("")
if command in ['music', 'Music']:
print("Genres:")
print("Rap")
print("Rock")
print("Pop")
print ("Country")
print("\t\t")
genre = input('What genre do you want to listen to?:')
if genre in ['Rap', 'rap', 'RAP']:
print("Songs (alphabetical order):")
if genre in ['Rock', 'rock', 'ROCK']:
print("Songs (alphabetical order):")
if genre in ['Pop', 'pop', 'POP']:
print("Songs (alphabetical order):")
So my question is how can I make it go back to the top (command)
Upvotes: 0
Views: 130
Reputation: 744
You have to loop until user decides to quit:
command = ""
while command.lower() != 'q':
command = input('Please enter a command or enter help for a list of commands (enter q to quit) :')
if command in ['help', 'Help', 'HELP', '?']:
print(" music Listen to music (XXXX songs)")
print(" ")
print("")
continue
if command in ['music', 'Music']:
print("Genres:")
print("Rap")
print("Rock")
print("Pop")
print ("Country")
print(" ")
genre = input('What genre do you want to listen to?:')
if genre in ['Rap', 'rap','RAP']:
print("Songs (alphabetical order):")
if genre in ['Rock', 'rock', 'ROCK']:
print("Songs (alphabetical order):")
if genre in ['Pop', 'pop','POP']:
print("Songs (alphabetical order):")
Upvotes: 1
Reputation: 51
It looks like you would need to surround your program in a while loop. Then have an option for them to exit the loop ending the program when they are finished.
Upvotes: 0