+ 1
Please help me with this code.
# Write a Python program to read an integer and find its reverse. Note: if user enter 1234 than the output should be 4321. while True: print("Enter a number to get the reverse of it: ") n = [] a = int(input()) n.append(a) b = n.reverse() print(b)
5 odpowiedzi
+ 5
Shrish Kumar Saini , there is also an other way to do this task, without using string conversion:
reversed_number = 0
n = 128
while n > 0:
dig = n % 10
n //= 10
reversed_number = reversed_number * 10 + dig
print(reversed_number)
+ 3
your list will contain the inputed number. reversing a list of one item wil not do something.
n = [1234]
after reversing it it will stay
n = [1234]
try to convert the number to string and then reverse that string and convert reverted string back to integer.
n = str(a)
n.reverse()
n = int(n)
print(n)
or just do this:
a = input()
a.reverse()
a = int(a)
print(a)
+ 2
The easiest route is to convert to string, flip it then convert back to integer🤷
Check this code
https://code.sololearn.com/cTgx4gYfpto8/?ref=app
+ 2
thank you everyone :)
+ 1
You can simply do:
word = str(input())
word = word[::-1]
print(word)