#Z13204. 计算邮资

计算邮资

Description

Calculate the postage based on the weight of the mail and whether the user opts for expedited shipping. The calculation rules are as follows:

  • If the weight is within 1000 grams (inclusive), the base fee is 8 yuan.
  • For any weight exceeding 1000 grams, an additional overweight fee of 4 yuan is charged for every 500 grams or part thereof.
  • If the user selects expedited shipping, an extra 5 yuan is added.

Input Format

The input consists of one line containing an integer and a character, separated by a space. The integer represents the weight (in grams), and the character indicates whether expedited shipping is chosen:

  • 'y' for yes (expedited).
  • 'n' for no (not expedited).

Output Format

Output one line containing an integer, which represents the total postage.

weight, urgent = input().split()
weight = int(weight)
base_fee = 8
extra_fee = 0

if weight > 1000:
    excess = weight - 1000
    extra_units = (excess + 499) // 500  # Equivalent to math.ceil(excess / 500)
    extra_fee = extra_units * 4

total = base_fee + extra_fee
if urgent == 'y':
    total += 5

print(total)
1200 y

17