航空行李收费计算器:Python 代码示例及流程图
以下是该收费函数的 Python 代码:
def calculate_fee(is_domestic, weight, is_first_class, is_disabled):
fee = 0
if weight <= 30:
return fee
if is_domestic:
if is_first_class:
fee = (weight - 30) * 4
else:
fee = (weight - 30) * 6
else:
fee = (weight - 30) * 6 * 2
if is_disabled:
fee = fee / 2
return fee
is_domestic = input('是否是国内客户?(是/否): ').lower() == '是'
weight = float(input('行李重量(公斤): '))
is_first_class = input('是否是头等舱?(是/否): ').lower() == '是'
is_disabled = input('是否是残疾客户?(是/否): ').lower() == '是'
fee = calculate_fee(is_domestic, weight, is_first_class, is_disabled)
print('费用(元):', fee)
程序流程图如下:
输入是否是国内客户?(是/否) -> 是 --------+
|
输入行李重量(公斤) ----------------------+
|
输入是否是头等舱?(是/否) ----------------+
|
输入是否是残疾客户?(是/否) ----------------+
|
计算费用(元) <----------------------------+
|
打印费用(元)
原文地址: http://www.cveoy.top/t/topic/pb09 著作权归作者所有。请勿转载和采集!