钻石价格计算器

经常计算钻石价格,拿着计算器点点点点的崩溃。不如Python直接写个小程序来的方便,于是发奋图强敲了10分钟。

代码如下

import re
import math
import requests
from prettytable import PrettyTable


def GET_USD_CNY():
    USD_CNY_URL = "https://www.huilv.cc/USD_CNY/"
    response = requests.get(USD_CNY_URL)
    USD_CNY_LIST = re.findall(r"<span class=back>([\s\S\n]{1,4})", response.text)
    USD_CNY = math.ceil(float(USD_CNY_LIST[0]) * 10) / 10
    return USD_CNY


def HETONG(dj, jz, dm, zje, hl):
    num = math.floor(float(zje / (dj * jz * hl + dm)))
    return num


if __name__ == "__main__":
    HUILV = GET_USD_CNY()
    DANJIA = float(input("单价(美元):"))
    JUNZHONG = float(input("均重(克拉):"))
    DAMO = float(input("打磨费(人民币):"))
    ZONGJINGE = float(input("总金额(人民币):"))
    LISHU = HETONG(DANJIA, JUNZHONG, DAMO, ZONGJINGE, HUILV)
    ZONGZHONG = round((ZONGJINGE - DAMO * LISHU) / (DANJIA * HUILV), 2)
    DiamondTable = PrettyTable(["单价(美元)", "汇率", "均重(克拉)", "总重量(克拉)", "粒数(颗)", "打磨费(元)", "总金额(元)"])
    DiamondTable.add_row([DANJIA, HUILV, JUNZHONG, ZONGZHONG, LISHU, DAMO, ZONGJINGE])
    print(DiamondTable)

使用方法很简单,就一直点、一直点,然后没有然后了!

tag(s): python
show comments · back · home
Edit with markdown

已有 2 条评论

  1. 遇深

    看了眼,是我用不起的代码

    遇深 February 18th, 2020 at 02:14 am回复
    1. Jamie

      我也刚学

      Jamie March 25th, 2020 at 03:25 am回复