一个特别的手机套餐包括50分钟的通 话时间和50条短信,每月15美元.每增加一分钟的通话时间,费用为0.25美元;每增加一条短信,费用为0.15美元。所有手机话费都包括额外的$0.44费用,用于支持911呼叫中心,整个账单(包括911费用)需要缴纳5%的销售税。
编写一个程序,读取用户在一个月内使用的分钟数和文本消息。显示基本收费、额外分钟收费(如有)、额外的短信费用(如有)、911费用、税金和账单总额。如果用户在这些类别中产生了费用,则只显示额外的分钟和文本消息费用。确保所有费用都用两位小数表示。
解答:
time = int(input("请输入本月通话时间"))
message = int(input("请输入本月短信条数"))
if time <= 50 and message<=50:
fire = float((15+0.44)*1.05)
elif time > 50 or message > 50:
if time > 50 and message < 50:
fire = float((15+0.44+(time-50)*0.25)*1.05)
elif message > 50 and time<50:
fire = float((15 + 0.44 + (message - 50) * 0.15) * 1.05)
else:
fire = float((15 + 0.44 + (time - 50) * 0.25+(message - 50) * 0.15) * 1.05)
print("您本月需缴纳的话费为%.2f" % fire)
notes:
注意在嵌套时 or 的用法,下面示例中逻辑关系是错误的。
time = int(input("请输入本月通话时间"))
message = int(input("请输入本月短信条数"))
if time <= 50 and message<=50:
fire = float((15+0.44)*1.05)
elif time > 50 or message > 50:
if time > 50 and message < 50:
fire = float((15+0.44+(time-50)*0.25)*1.05)
elif message > 50 and time<50:
fire = float((15 + 0.44 + (message - 50) * 0.15) * 1.05)
else:
fire = float((15 + 0.44 + (time - 50) * 0.25+(message - 50) * 0.15) * 1.05)
print("您本月需缴纳的话费为%.2f" % fire)