以下是一个用Python实现的示例代码: ```python # 设置初始账户余额 a_balance = 100 b_balance = 100 # 获取用户输入 card_type = input("请输入卡的类型(a卡或b卡):") duration = int(input("请输入通话时间(分钟):")) # 计算通话费用 if card_type == "a卡": if duration <= 3: cost = duration * 0.2 else: cost = 3 * 0.2 + (duration - 3) * 0.1 a_balance -= cost elif card_type == "b卡": cost = duration * 0.1 b_balance -= cost else: print("请输入有效的卡类型") # 输出通话费用和账户余额 print("通话费用为:", cost) if card_type == "a卡": print("a卡账户余额为:", a_balance) elif card_type == "b卡": print("b卡账户余额为:", b_balance) ``` 运行示例: ``` 请输入卡的类型(a卡或b卡):a卡 请输入通话时间(分钟):5 通话费用为: 0.5 a卡账户余额为: 99.5 ``` [2024-05-27 14:22:19 | AI写代码神器 | 537点数解答]