[英]in Python can i loop back to a specific line?
因此,我正在嘗試制作一個程序,用戶可以在其中輸入命令以到達他們要去的地方(啟動另一個程序,等等。),但是當他們輸入命令時,可以到達該命令的結尾(本節)和該程序停止運行
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):")
所以我的問題是如何使它回到頂部(命令)
您必須循環播放,直到用戶決定退出:
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):")
看來您需要在while循環中包圍程序。 然后,讓他們有一個選擇,可以在完成后退出循環,結束程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.