In this example we will show a simple method of printing out user’s input values in reverse order with Python.
Source Code
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
if __name__ == '__main__':
ptr = []
for i in range(5):
num = int(input('Please input a number:\n'))
ptr.append(num)
ptr.reverse()
# print out reversed list
print('Print out in a reverse order: ')
print(ptr)
Output:
Please input a number:
4
please input a number:
5
please input a number:
6
please input a number:
7
please input a number:
8
Print out in a reverse order: [8, 7, 6, 5, 4]