繁体   English   中英

Python - 根据已处理的验证检查确保客户收到准确的月度发票

[英]Python - To make sure that clients receive accurate monthly invoices based on verifications checks that have been processed

我大学的一种 Python 作业。 问题如下:-

一家公司正在寻求建立一个计费系统,以确保其所有客户都能收到基于已处理的验证(或“支票”)的准确月度发票。

您有以下结构的两个表:

| Check type              | Price | Currency |
|-------------------------|-------|----------|
| document_photo          | 0.5   | USD      |
| document_video          | 0.9   | USD      |
| facial_similarity_photo | 0.3   | USD      |
| facial_similarity_video | 0.8   | USD      |
| right_to_work           | 1.25  | USD      |
 
| client   | Check Type              | Result    |
|----------|-------------------------|-----------|
| ABC Bank | facial_similarity_video | pass      |
| ABC Bank | facial_similarity_video | fail      |
| XYCoin   | document_photo          | bad_input |
| XYCoin   | facial_similarity_photo | pass      |
| XYCoin   | document_photo          | pass      |
 

给定以下输入,计算给定供应商的发票。 为了简化问题,您不必关注任何特定时间段:

Input:
pricing = [{"check_type": "document_photo", "price":0.5, "currency":"USD"},
    {"check_type": "document_video", "price":0.9, "currency":"USD"},
    {"check_type": "facial_similarity_photo", "price":0.3, "currency":"USD"},
    {"check_type": "facial_similarity_video", "price":0.8, "currency":"USD"},
    {"check_type": "right_to_work", "price":1.25, "currency":"USD"}]
 
checks = [{"client": "ABC Bank", "check_type": "facial_similarity_video", "result": "pass"},
    {"client": "ABC Bank", "check_type": "facial_similarity_video", "result": "fail"},
    {"client": "XYCoin", "check_type": "document_photo", "result": "bad_input"},
    {"client": "XYCoin", "check_type": "facial_similarity_photo", "result": "pass"},
    {"client": "XYCoin", "check_type": "document_photo", "result": "pass"}]    


  Test cases:     
    calculate_invoice("ABC Bank") == 1.6    
    calculate_invoice("XYCoin") == 0.8 

我试过在下面这样做:-

counts = [pricing, checks]
calculate_invoice = 0

for key in set(pricing).intersection(set(checks)):
    for i in counts:
        if i[key] == 'pass':
            calculate_invoice += i[key].get('price')
            

print(calculate_invoice)

但是我在下面收到了这个错误:

Traceback (most recent call last): 
    File "main.py", line 17, in for key in set(pricing).intersection(set(checks)): 
TypeError: unhashable type: 'dict'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM