我有一本代表书店的字典。键表示书名,值表示当前书籍的份数。从商店出售书时,书的份数必须减少。
我已经写了一个代码来减少已售出图书的拷贝数,但在更新后打印词典时,我得到的是初始词典,而不是更新后的词典。n=input("Enter number of books in shop:")
book_shop={} #Creating a dictionary book_shop
#Entering elements into the dictionary
for i in range(n):
book_title=raw_input("Enter book title")
book_no=input("Enter no of copies")
book_shop[book_title]=book_no
ch=raw_input("Do you want to sell")
if (ch in 'yesYES'):
for i in range(n):
print"which book you want to sell??",book_shop
ch1=raw_input("choice")
if(book_shop.keys()[i]==ch1):
book_shop.keys()[i]=(book_shop.values()[i]-1)
break
print book_shop
我想用最简单的方法解决这个问题。我是否遗漏了代码中的任何逻辑或行?