by CodeChum Admin
Did you know that you can also reverse lists and group them according to your liking with proper code? Let's try it to believe it.
Instructions
Input
The first line contains an odd positive integer.
The next lines contains an integer.
5
1
3
4
5
2
Output
A line containing a list.
[2,5]-[4]-[3,1]
import random
rand_list=[]
n=int(input("Enter an odd number: "))
for i in range(n):
rand_list.append(random.randint(3,9))
print(rand_list)
reversed_list=rand_list[::-1]
print(reversed_list)
print("[",reversed_list[0],reversed_list[1],"]","[",reversed_list[2],"]","[",reversed_list[3],reversed_list[4],"]")
Comments
Leave a comment