Answer to Question #259659 in Python for Pau

Question #259659

We've already made arraying/listing the easy way, but how about arraying/listing and printing the list in reverse order?


Make a program that will input an integer and then using loops, add items on an array/list one by one for the same number of times as that of the first inputted integer. Then, print out the array/list in reverse order, that is, starting from the last item on the array/list down to the first one, each in separated lines.


Input

The first line contains the size of the array/list.

The next lines contains the items of the array/list (integers).

5
1
64
32
2
11

Output

Multiple lines containing integers.


11
2
32
64
1
1
Expert's answer
2021-11-03T17:48:21-0400


SOLUTION FOR THE ABOVE QUESTION


SOLUTION CODE


#propmt the user to enter the number of elements in his/her list
number_of_list_elements = int(input("\nEnter the number of elements: "))
#declare a list to append the elements
my_list = []

for i in range(0,number_of_list_elements):
    element = int(input("Enter element "+str(i+1)+": "))
    my_list.append(element)

#print("\nThe original list is "my_list)
#Now lets print the reversed list
print("\nOutput: ")
for i in range(0,number_of_list_elements):
    element = number_of_list_elements -(i+1)
    print(my_list[element])



SAMPLE PROGRAM OUTPUT






Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog