Python输入

77 阅读1分钟

带空格的输入

input().split() 将输入按照空格分隔,返回一个字符串列表。

map(int, *) 将 int 函数作用于每一个列表元素。

a,b,c=3,5,6
d,e,f=map(int, input().split())
print(a)
print(b)
print(c)
print(d)
print(e)
print(f)
1 2 3
3
5
6
1
2
3

14:计算邮资

OpenJudge - 14:计算邮资

根据邮件的重量和用户是否选择加急计算邮费。计算规则:重量在1000克以内(包括1000克), 基本费8元。超过1000克的部分,每500克加收超重费4元,不足500克部分按500克计算;如果用户选择加急,多收5元。

a, b = input().split()
a = int(a)
cost = 0

if a <= 1000:
    cost = 8
else:
    cost = 8
    a -= 1000
    t = a // 500
    cost = cost + t * 4
    if a % 500 != 0:
        cost = cost + 4
if b == "y":
    cost = cost + 5
print(cost)