solution

Create a Python program that allows the user to enter a number and reverses it. If the
number entered 45632, the program must produce the following output: 23654.

this is my answer but i dont know how to write a code to get the reverse of a negative number :-123 reversed number -321.

num = int(input(‘nEnter a number: ‘))
reversed_num = 0

while num != 0:
digit = num % 10 # remainder of the number inputted from the user divided by 10.
reversed_num = reversed_num * 10 + digit # Variable value changed. it is changed to its value
# multiplied by 10 plus the value of digit
num //= 10 # rounds the number down to the nearest whole number. This keeps the loop from becoming an infinite loop.
# output
print(“nReversed Number: ” + str(reversed_num)) # prints the number as a string and not a value

 
"Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"
Looking for a Similar Assignment? Our Experts can help. Use the coupon code SAVE30 to get your first order at 30% off!

Hi there! Click one of our representatives below and we will get back to you as soon as possible.

Chat with us on WhatsApp