[Python] 纯文本查看 复制代码 def calculate_apple(weight, volume, quantity):
if quantity >= 20:
return (weight / 2 * 3 + volume / 4 * 5 + 6)
else:
return (weight / 3 * 4 + volume / 5 * 6 + 7)
def calculate_banana(weight, volume, quantity):
# 假设香蕉的计算公式与苹果不同,这里需要您提供具体的公式
# 例如:
return weight * 2 + volume * 3 + quantity * 4
def calculate_peach(weight, volume, quantity):
# 假设桃子的计算公式与苹果不同,这里需要您提供具体的公式
# 例如:
return weight * 1.5 + volume * 2.5 + quantity * 3
def main():
while True:
print("请输入数字选择公式序号:1.苹果 2.香蕉 3.桃子")
choice = input()
if choice not in ['1', '2', '3']:
print("无效的选择,请重新输入。")
continue
print("请输入重量:")
weight = float(input())
print("请输入体积:")
volume = float(input())
print("请输入件数:")
quantity = int(input())
if choice == '1':
cost = calculate_apple(weight, volume, quantity)
elif choice == '2':
cost = calculate_banana(weight, volume, quantity)
elif choice == '3':
cost = calculate_peach(weight, volume, quantity)
print(f"公式的运算结果是:{cost}")
print("===========================================")
# 询问用户是否继续
continue_choice = input("是否继续计算?(y/n): ")
if continue_choice.lower() != 'y':
break
if __name__ == "__main__":
main() |