1# Get the number from user manually
2num = int(input("Enter your favourite number: "))
3
4# Initiate value to null
5test_num = 0
6
7# Check using while loop
8
9while(num>0):
10 #Logic
11 remainder = num % 10
12 test_num = (test_num * 10) + remainder
13 num = num//10
14
15# Display the result
16print("The reverse number is : {}".format(test_num))
17
1# Python string/number reverser
2example_number = 12143
3example_string = "Hello there"
4
5def reverse(thing):
6 thing = str(thing) # convert it to a string, just in case it was a number
7 list_of_chars = [char for char in thing]
8 reversed_list_of_chars = []
9 x = -1
10
11 for char in list_of_chars:
12 reversed_list_of_chars.append(list_of_chars[x])
13 x += -1
14
15 reversed_thing = ''.join(reversed_list_of_chars)
16
17 return reversed_thing
18 # Or alternatively do:
19 print(reversed_thing)
20
21# Run it by doing this
22reverse(example_number)
23reverse(example_string)