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]
# Create a variable that accepts a positive odd integer.
n = int(input())
if n < 0 or n%2 == 0:
print*=("Number not positive or not odd")
exit()
# Create an empty list
L = []
# Using loops, add random integer values into the list one by one
for _ in range(n):
x = int(input())
L.append(x)
# Reverse the order of the list
L.reverse()
# print out the list's new order
m = n//2
print(L[:m], L[m:m+1], L[m+1:], sep='-')
Comments
Leave a comment