在我的类(class)中,我们被要求为音乐组织者创建一个包含三个选项的菜单,下面的代码是我整个代码的一部分。每当我运行该程序时,我都不会出错,但是当我输入 1 时,终端只会再次弹出选项菜单,而不是“输入艺术家姓名:”
知道为什么吗?
#创建选项菜单
option = 0
while option != 3:
print("What would you like to do?")
print(" 1. count all the songs by a particular artist")
print(" 2. print the contents of the database")
print(" 3. quit")
option = int(input("Please enter 1, 2, or 3: "))
# For option 1: find a all the songs on a certain album
if option == 1:
# Set the user input to a variable
Artistname = str("Enter artist name: ")
artistFound = False
for i in range(len(artistList)):
# For all the artist names in the list, compare the user input to #the artist names
if artistList[i] == Artistname:
artistFound = True
# count songs associate with artist
number+=1
print(count, "songs by",artistList[i])
# If the user input isn't in the list, then print out invalid
if artistFound == false:
print("Sorry, that is not an artist name")
最佳答案
试试这个获取用户输入
Artistname =input("Enter artist name: ")
使用 break 退出 while 循环或按 3
关于python - 当我尝试从我创建的菜单中选择特定选项时,它只是再次输出菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33539282/