在我的python程序中获取类型错误?

2024-10-03 00:31:58 发布

您现在位置:Python中文网/ 问答频道 /正文

import sqlite3

Book = sqlite3.connect("BookStore.db")
curbook = Book.cursor()
more=True
total_cost = 0.0
while(more):   
    Title = input("Enter Title of the book : ")
    curbook.execute("SELECT title,author,price FROM BookDetails WHERE title = '"+ Title +"';")
    record = curbook.fetchone()
    if record ==  None:
        print("No Record Found")
        break
    else :  
        print(record)
        no_of_copies = int(input("Enter Number of copies you want to purchase : "))
        More = input("Add more books? Y/N")
        if More == 'n' or More == 'N':
            more = False
        curbook.execute("SELECT price from BookDetails WHERE title = '"+ Title +"';")
        price = curbook.fetchone()
        total_cost = total_cost + no_of_copies * price
        print("Total Cost ",total_cost)
Book.close()

错误:

Traceback (most recent call last):
  File "C:\Python35\Retrieve_Book.py", line 21, in <module>
    total_cost = total_cost + no_of_copies * price
TypeError: unsupported operand type(s) for +: 'float' and 'tuple'

Tags: ofnoinputtitlemorerecordpricetotal