如何查看员工选择的特定日期内每位客户下的订单数量?

2024-07-04 08:00:20 发布

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

import uuid  # GET A RANDOM ID FOR THE CUSTOMER
from datetime import date  # GET CURRENT DATE

TodayDate = date.today()
Dates = {}

我的想法是使用Dates字典来保存和打印员工选择的特定日期总共下了多少订单

Customers = {}

FirstEmployeeAccountUsername = "coffee1"
FirstEmployeeAccountPassword = "coffeeshop1"
SecondEmployeeAccountUsername = "coffee2"
SecondEmployeeAccountPassword = "coffeeshop2"
ThirdEmployeeAccountUsername = "coffee3"
ThirdEmployeeAccountPassword = "coffeeshop3"

print("Welcome to our coffee shop!")
print("Login")

# EMPLOYEE LOGIN PROCESS STARTS
LoginEnter = True
while LoginEnter:
    username = input("Username: ")
    password = input("Password: ")
    if username == FirstEmployeeAccountUsername and password == FirstEmployeeAccountPassword or username == SecondEmployeeAccountUsername and password == SecondEmployeeAccountPassword or username == ThirdEmployeeAccountUsername and password == ThirdEmployeeAccountPassword:
        print("Login Successful")
        LoginEnter = False
    else:
        print("Invalid Login. Try again")
# EMPLOYEE LOGIN PROCESS ENDS

这里我得到了一个特定客户总共下了多少订单

# PROCCESS AFTER ORDER PLACEMENT STARTS
while True:
    CustomerName = input("Customer's Name:")
    CustomerAddress = input("Customer's Address:")


    if CustomerName in Customers:
        Customers[CustomerName]['Orders'] += 1
    else:
        Customers[CustomerName] = {}
        Customers[CustomerName]['Address'] = CustomerAddress
        Customers[CustomerName]['ID'] = uuid.uuid1()
        Customers[CustomerName]['Orders'] = 1


    print("This customer has ordered {} time(s)".format(Customers[CustomerName]['Orders']))

    print("Current Date is: {}".format(TodayDate))
    OrderPrice = input("Total amount of order:")

这是我当前获得的输出:Output of code


Tags: andimportidinputgetdateuuidusername
1条回答
网友
1楼 · 发布于 2024-07-04 08:00:20

只要使用与下订单时计算客户订单相同的逻辑即可。您可以使用date.toordinal()作为dict键,这将返回一个表示日期的整数:TodayKey = date.toordinal(date.today())

下单前:

if TodayKey not in Dates:
    Dates[TodayKey] = {}

按每个顺序:

if CustomerName not in Dates[TodayKey]:
    Dates[TodayKey][CustomerName] = 1
else:
    Dates[TodayKey][CustomerName] += 1

相关问题 更多 >

    热门问题