简体   繁体   English

如何将数字添加到列表中的所有整数(python)

[英]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 what you want is to add an int to each element of your list, you can probably find an answer here .如果您想要为列表的每个元素添加一个int ,您可能可以在此处找到答案。 Anyways, try something like:无论如何,尝试类似:

for i in range(len(a)):
    a[i] += manat

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.

相关问题 如何将一个列表中的所有整数添加到另一个列表中的整数,并在Python中以相同的顺序使用不同的长度? - How do I add all integers in one list to integers on another list with different length in the same order in Python? 使用 Python,如何将列表中的所有匹配整数相乘,然后将剩余的整数相加 - Using Python, how can I multiply all matching integers in a list and then add the remaining integers 如何在Python中获取列表中的所有最高整数 - How to get all the highest integers in a list in Python 如何在 Python 中将一个列表中的整数添加到另一个列表中 - How to add the integers in one list to another in Python Python - 如何添加整数(可能在列表中?) - Python - how to add integers (possibly in a list?) 如何将原始输入数字转换为python中的整数列表? - How to convert raw input number to a list of integers in python? 如何在 Python 中创建一个包含随机数的随机整数的列表 - How to create a list with a random number of random integers in Python Python。 如何总结列表中的所有偶数? - Python. How to sum up all even integers in a list? 如何将列表中的所有整数相乘? - 蟒蛇 - How do I multiple all integers in a list? --Python 如何切片列表中的所有整数? - How to slice all integers in a list?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM