【发布时间】:2020-12-13 01:37:18
【问题描述】:
我刚开始学习 Python 正在努力学习。
程序的概念是咖啡店接受订单的“应用程序”[![在此处输入图片描述][1]][1]
if Customer_Name in Customers:
Customers[Customer_Name]['Orders'] += 1
Customers[Customer_Name]['TotalAmount'] = Total_Amount
else:
Customers[Customer_Name] = {}
Customers[Customer_Name]['Name'] = Customer_Name
Customers[Customer_Name]['Address'] = Customer_Address
Customers[Customer_Name]['ID'] = uuid.uuid1()
Customers[Customer_Name]['Orders'] = 1
Customers[Customer_Name]['TotalAmount'] = 0
print(Customer_Name, "has ordered {} time(s)".format(Customers[Customer_Name]['Orders']))
if Customers[Customer_Name]['TotalAmount'] == 0:
print("This is the first time", Customer_Name, "orders")
else:
print(Customer_Name, "has spent", Customers[Customer_Name]['TotalAmount'], "in total")
print("Current Date is: {}".format(Today_Date))
Order_Price = float(input("Total amount of order:"))
Total_Amount = Order_Price + Total_Amount
if Print_Today != Today_Date:
print("Total amount of orders today is: ", float(Total_Amount))
answer1 = input("Send another order? (Y/N)").lower()
process2 = answer1 == "y"
LengthCustomersList = len(Customer_List)
length += 1
in_list += 1
file.write(str(Customer_List[0:]) + '\n') # TAKE CARE FOR DUPLICATE NAMES FROM SAME ADDRESS
file1.write(Customer_Name + " has ordered " + str(Customers[Customer_Name]['Orders']) + " times in total\n")
# FIX DUPLICATES SAME NAME SAME ADDRESS
csv_writer = DictWriter(open('data_entered.csv','a'), fieldnames=['Customer Name', 'Customer Address', 'Customer ID', 'Total Orders',
'Total Amount'])
csv_writer.writeheader()
csv_writer.writerows([{'Customer Name': Customers[Customer_Name]['Name'],'Customer Address': Customers[Customer_Name]['Address'],
'Customer ID': Customers[Customer_Name]['ID'],
'Total Orders': Customers[Customer_Name]['Orders'],
'Total Amount': Customers[Customer_Name]['TotalAmount']}]) # TOTAL AMOUNT= 0 IF NOT MORE THAN 2 TIMES ORDER
if int(length) == int(LengthCustomersList):
process1 = False
file.close()
file1.close()
file2.close()
这是我目前得到的输出
[![输出][2]][2]
问题是:为什么它只导入输入两次的名字,而不是 Michelle 在这种情况下。
附注*。我想了解如何解决这个问题。所以请不要直接给我解决方案
【问题讨论】:
-
请修正代码缩进,对 Python 来说正确至关重要。
-
现在应该不错了。
标签: python python-3.x csv