[英]How to add number to all integers in list (python)
a = [5,7,11,2,6,8]
print('Toplanılanlar: pleyer , telefon, hiroskuter, it, kompüter, 3d-printer')
print(a)
print('Bütün toplanılan neçə manat artdı?')
manat = input()
for i in range(6):
#i need smthng to add here
print('Toplanılanların yenilənmiş siyahısı:')
print(a)
Probably you're looking for可能你正在寻找
manat = int(input())
for i in len(a):
a[i] += manat
Or form a new list:或者形成一个新列表:
manat = int(input())
new_lst = [item + manat for item in a]
if I have understood your question, your answer is something like this:如果我理解了你的问题,你的答案是这样的:
a = [5, 7, 11, 2, 6, 8]
for i in range(len(a)):
a[i] += 1
so the result will be:所以结果将是:
a = [6, 8, 12, 3, 7, 9]
With your prompts written in Azerbaijani, it's not obvious what you are trying to do (at least not for us people who don't speak that language).您的提示是用阿塞拜疆语写的,您要做什么并不明显(至少对于我们不会说这种语言的人来说)。
In all cases, it is not necessary to loop on a range.在所有情况下,都没有必要在范围上循环。
If you are prompting the user for a single number that will increase all counts by the same amount:如果您提示用户输入一个数字,该数字将使所有计数增加相同的数量:
a = [ c + int(manat) for c in a ]
If you are prompting the user for a list of 6 increments applying to each count respectively:如果您提示用户输入分别应用于每个计数的 6 个增量的列表:
a = [ c + int(i) for c,i in zip(a,manat.split()) ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.