list(map(int,input().split()))

a = list(map(int, input().split()))
# 创建一个列表,使用 split() 函数进行分割
# map() 函数根据提供的函数对指定序列做映射,就是转化为int型

如果不加map()
报错
Traceback (most recent call last):
File “D:/honggeng/practise/例2.py”, line 11, in
a = int(input().split())
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list’

map()

描述
map() 会根据提供的函数对指定序列做映射。

第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 function 函数返回值的新列表。

语法
map() 函数语法:

map(function, iterable, …)

>>> def square(x) :         # 计算平方数
...     return x ** 2
...
>>> map(square, [1,2,3,4,5])    # 计算列表各个元素的平方
<map object at 0x100d3d550>     # 返回迭代器
>>> list(map(square, [1,2,3,4,5]))   # 使用 list() 转换为列表
[1, 4, 9, 16, 25]
>>> list(map(lambda x: x ** 2, [1, 2, 3, 4, 5]))   # 使用 lambda 匿名函数
[1, 4, 9, 16, 25]
>>>

input().split()

username, passwd = input("用户名,密码:").split()   
# 注意input() 的返回类型是str
print(username,passwd)

结果

用户名,密码:hong 123
hong 123

例子

'''
小明和我参加班长的选举投票,投票人数为n,每人可以投K票,
第一行输入为投票人数,第二行输入为每个人投给小明的票数求保证我能获胜最小的K。
例如下面的示例,由于小明获得1+1+1+5+1=9票,则我获得4+4+4+0+4=12票,我获胜,此时5最小。
输入:
5
1 1 1 5 1
输出:
5
'''
n = int(input())
a = list(map(int, input().split()))
sum = 0
ans = 0
for i in a:
 if i>ans:
     ans = i
 sum+=i
while((ans*n-sum)<=sum):
 ans+=1
print(ans)
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐