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'
答案 0 :(得分:3)
price
是一个元组
尝试:
total_cost = total_cost + no_of_copies * price[0]