+ 1

Array in Python

Can someone please help me with the below problem in python? I will upload my code shortly. Thanks...... Given an array A of N numbers, you have to write a program which 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]. Input Format: The first line of the input contains a number N representing the number of elements in array A. The second line of the input contains N numbers separated by a space. (after the last elements, there is no space) Output Format: Print the resultant array elements separated by a space. (no space after the last element) Example: Input: 4 2 5 3 1 Output: 3883 Explanation: Here array A is [2,5,3,1] os reverse of this array is [1,3,5,2] and hence the resultant array is [3,8,8,3] code by Tortello https://code.sololearn.com/c77AD7CfGqdX/?ref=app

13th Feb 2019, 7:19 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
7 Respostas
+ 2
A = [2, 5, 3, 1] s = list(i+j for i, j in zip(A, reversed(A))) print(s)
13th Feb 2019, 7:36 PM
Pedro Tortello
Pedro Tortello - avatar
+ 3
HonFu never thought in this perspective. But one who's going to "cheat" in homework will never be a good programmer... or employee. Or person.
13th Feb 2019, 7:49 PM
Pedro Tortello
Pedro Tortello - avatar
+ 2
Tortello, we should not give the whole solution to a problem here in q&a but rather hints how they can solve it on their own. Otherwise q&a will be overrun by school classes from all over the world posting their homework here.
13th Feb 2019, 7:43 PM
HonFu
HonFu - avatar
+ 2
Yeah, but/because of that we shouldn't support it anyway. For the sake of all of us.
13th Feb 2019, 7:57 PM
HonFu
HonFu - avatar
+ 1
thanks a lot Tortello 😀😀
13th Feb 2019, 7:39 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
+ 1
Tortello why did you use the zip function???
14th Feb 2019, 4:11 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
+ 1
Nilutpol Kashyap to pair each item in the lists "A" and "reversed (A)" to the variables i and j, respectively.
14th Feb 2019, 4:16 PM
Pedro Tortello
Pedro Tortello - avatar