Print reverse order

Asked

Viewed 174 times

1

Given a number x, where 1000 x<10000, prints the number x with its digits in reverse order. For example: x = 2736, the answer will be 6372.

x=float(input()) 
x=float(x)
if (x >= 1000 and x < 10000):  
print("%.f"%x)

I can’t get it to be in reverse order, I mean if it goes in with 1234 goes out 1234 and not 4321 as I should...?

2 answers

0


Try it like this:

x = float(input()) 
if (x >= 1000 and x < 10000):  
  y = str(x)
  print(y[::-1])

-1

Follows a function to perform the inversion:

def reverse_number(n):
  r = 0
  while n > 0:
    r *= 10
    r += n % 10
    n /= 10
  return r
  • Ok, but is there any way you could edit mine? wanted to learn better from the point I made...would have like? grateful

  • Your output: 0.5658 Correct output: 5658

  • It’s straight but has a 0. that can not have, as strip?

  • Instead of using float you should use int

  • Thank you very much you are myths

Browser other questions tagged

You are not signed in. Login or sign up in order to post.