```python def calculate_postage(weight, is_urgent): # 计算基本费用 postage = 8 # 计算超重部分的费用 if weight > 1000: overweight = (weight - 1000) // 500 if (weight - 1000) % 500!= 0: overweight += 1 postage += overweight * 4 # 如果加急,加收 5 元 if is_urgent == 'y': postage += 5 return postage # 接收输入 weight, urgent = input().split() weight = int(weight) # 调用函数计算邮费并输出 print(calculate_postage(weight, urgent)) ``` 额外注意点: 1. 输入数据的合法性检查,比如重量是否为正整数,加急标志是否为 'y' 或 'n'。 2. 考虑对代码进行异常处理,以防出现不可预见的错误。 3. 可以添加一些注释,增强代码的可读性。 [2024-12-31 19:36:29 | AI写代码神器 | 244点数解答]