"""2.1-2.4 课后练习：代码格式、变量、输入与输出。

要求：
1. 只修改 TODO 标记的位置。
2. 每部分先在注释中写出预测，再运行。
3. 最终文件应从上到下一次运行，不出现异常。
"""

print("=" * 64)
print("第一部分：变量名体检")

# TODO 1：根据课堂规则填写四个判断结果；不需要调用额外函数。
sales_quantity_legal = False
two_price_legal = False
class_legal = False
unit_price_legal = False

print("sales_quantity 合法：", sales_quantity_legal)
print("2price 合法：", two_price_legal)
print("class 合法：", class_legal)
print("unit_price 合法：", unit_price_legal)

print("\n第二部分：建立一条商品记录")

# TODO 2：填写商品名称，类型为 str。
product_name = "请填写"

# TODO 3：填写销售数量，类型为 int，建议使用 3。
sales_quantity = 0

# TODO 4：填写单价，类型为 float，建议使用 19.9。
unit_price = 0.0

print("商品：", product_name)
print("数量：", sales_quantity, type(sales_quantity))
print("单价：", unit_price, type(unit_price))


print("\n第三部分：模拟 input() 并转换")

quantity_text = "3"
price_text = "19.9"

# TODO 5：把 quantity_text 转为 int。
quantity = 0

# TODO 6：把 price_text 转为 float。
price = 0.0

# TODO 7：计算销售额。
total = 0.0

print("原始输入类型：", type(quantity_text), type(price_text))
print("转换后类型：", type(quantity), type(price))
print(f"销售额：{total:.2f} 元")


print("\n第四部分：print() 格式")

# TODO 8：使用 sep=" | " 输出 product_name、quantity、price。
print("请修改这一行")

# TODO 9：使用 f-string 输出“商品名 × 数量 = 金额”，金额保留两位小数。
print("请修改这一行")


print("\n第五部分：购物小票")


def print_receipt(product, quantity, unit_price):
    """输出购物小票并返回总额。"""
    # TODO 10：计算 total。
    total = 0.0

    print("=" * 30)
    print("       商务数据训练商店")
    print("-" * 30)
    # TODO 11：依次输出商品、数量、单价和合计；金额保留两位小数。
    print("商品：请修改")
    print("数量：请修改")
    print("单价：请修改")
    print("合计：请修改")
    print("=" * 30)
    return total


receipt_total = print_receipt(product_name, quantity, price)
print("函数返回值：", receipt_total)


print("\n第六部分：植树证书")


def print_tree_certificate(nickname, plant_name, certificate_id):
    """根据三个参数输出证书。"""
    print("╔" + "═" * 32 + "╗")
    print("║          植 树 证 书           ║")
    print("╠" + "═" * 32 + "╣")
    # TODO 12：使用三个参数输出申请人、植物和编号。
    print("  申请人：请修改")
    print("  植物：  请修改")
    print("  编号：  请修改")
    print("╚" + "═" * 32 + "╝")


print_tree_certificate("小数同学", "梭梭树", "TREE-2026-0722")


print("\n第七部分：解释与自检")

# TODO 13：在下方注释中解释 = 与 == 的区别。
# 解释：

# TODO 14：在下方注释中解释为什么 "19.9" * 3 不是数值乘法。
# 解释：

# 自检：
# [ ] 所有变量名合法且含义明确。
# [ ] quantity 是 int，price 与 total 是 float。
# [ ] 小票金额由程序计算，不是手工填写。
# [ ] 证书变化字段通过参数传入。
# [ ] 程序可以从上到下一次运行。
