python - 当我尝试从我创建的菜单中选择特定选项时,它只是再次输出菜单

标签 python loops count increment

在我的类(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/

相关文章:

javascript - 如何在网页中执行 "javascript:__doPostBack"以使用 selenium 下载 pdf 文件?

c++ - for循环跳过getline

sql - 按时间间隔对事件进行分组和计数,以及运行总计

jQuery 计算 div 中的字符数?

python - 返回数据框中每对行之间的获胜行

python - 为什么使用 lambda 函数将其设为属性?

python - 为什么使用 Flask Mail 发送的文本附件是空的?

java - For 循环 - HashMap 的第一个参数

android - Java 中使用 count() 过滤 Realm

php - 计算从 PHP `mysql_query` 函数返回的行数的可靠方法是什么?