变量未包含在 SQLite select 语句 Python 中

Variable is not incorporating in SQLite select statement Python

我向用户询问预算价格并将将该值分配给一个变量。我打算在 SQLite 的 SELECT 语句中使用变量。用户输入数字后,程序会引发错误,其中数字超出了先前函数的范围。

    def display_data_condition(connection):
        prices = float(input('What is your budget? '))
        cursor = connection.execute('SELECT Title, Price FROM Book WHERE Price <= (?)', prices)
        print("{:<10} {:<10}".format('Book Title', 'Number of Copies Available'))
        for row in cursor:
            print("{:<10} {:<10}", row[1], row[4])
        print('')
    

    def display_statements(connection):
        while True:
            try:
                print('Display Options')
                print('1) Display data')
                print('2) Display Data Based on a Condition')
                print('3) Display the total number of books written by each author')
                print('4) Display the average price of all books in the inventory')
                print('5) Display the title of the book that has the most number of copies')
                print('6) Return to Menu')
                print('')
                choice = int(input('Which display option would you like to use? '))
                if 1 < choice > 6:
                    raise ValueError
                if choice == 1:
                    display_all_data(connection)
                elif choice == 2:
                    display_data_condition(connection)
                elif choice == 3:
                    display_number_books_by_author(connection)
                elif choice == 4:
                    display_average_price(connection)
                elif choice == 5:
                    book_most_number_of_copies(connection)
                elif choice == 6:
                    return
            except ValueError:
                print('Incorrect User Input. Please enter a number between 1 and 6')

我在 display_data_condition 函数中注释掉了 select 语句和光标打印,它似乎可以正常工作。

此查询 SELECT Title, Price FROM Book.... 选择两列。因此 row 有 2 个元素,row[0] 是标题,row[1] 是价格。没有row[4]