Given an array?A
?of?N
?numbers (integers), you have to write a program that prints the sum of the elements of array?A
?with the corresponding elements of the reverse of array?A
. If array?A
?has elements?[1, 2, 3]
, then reverse of the array?A
?will be?[3, 2, 1]
?and the resultant array should be?[4, 4, 4]
.
from array import *
vals=array('i', [1,2,3 ])
vals2=array('i', [])
vals2.typecode=vals.reverse()
newArr=array(vals.typecode,(a+vals2 for a in vals))
for e in newArr:
print(e)
output:
Traceback (most recent call last):
File "E:/colg/python/Fristpro.py", line 7, in <module>
vals2.typecode=vals.reverse()
AttributeError: attribute 'typecode' of 'array.array' objects is not writable
question from:
https://stackoverflow.com/questions/65559619/addition-of-elements-of-array-in-python-array-array 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…