[英]in Python can i loop back to a specific line?
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) 所以我的问题是如何使它回到顶部(命令)
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):")
It looks like you would need to surround your program in a while loop. 看来您需要在while循环中包围程序。 Then have an option for them to exit the loop ending the program when they are finished. 然后,让他们有一个选择,可以在完成后退出循环,结束程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.