Computer Science, asked by ishubagri, 1 year ago

write a python script to read an integer >1000 and reverse the number..... plz answer..... ​


rakeshchennupati143: r u there?

Answers

Answered by rakeshchennupati143
29

Program:

number = int(input("Enter a number Greater than 1000 : "))

if number < 1000 :

     print("Enter number greater than 1000")

else :

     print("The revere of ",number," is :")

     string = str(number)

     print(string[ ::-1])

Output-1:

Enter a number Greater than 1000 : 12356

The revere of  12356  is :

65321

Output-2:

Enter a number Greater than 1000 : 123

Enter number greater than 1000

Explanation:

  • first i took number into number variable
  • then i check if the given number is greater than 1000 or not
  • if true then i printed the statement
  • if false then i converted given number into string and printed the reverse of the string directly using String's predefined notation which is [a:b:c]
  • which means count in increments of c starting at a inclusive, up to b exclusive
  • if a and b are not given and c is in negative then the count will start from last character of the string and then goes on until it reaches the start of the string
  • so that's how the string will be reversed and the reversed number will be printed

---Hope you got what you wanted, if you like mark as brainliest, it would really help me.   :)


ashwin456ojha: i said that, could we reverse the number by using FOR loop?
ashwin456ojha: in the else block
rakeshchennupati143: yes but it looks like a normal way that everyone does
rakeshchennupati143: u said python so i added some pythonish code
rakeshchennupati143: to be different from others
ashwin456ojha: OK! :)
ashwin456ojha: Actually, I love Python!!! I've learned so many tuts, now I'm learning each string methods of it!!!
ashwin456ojha: I'll surely ask from you, if I need any help in it!!
rakeshchennupati143: yea i would love to help other glad my program is helpful to you :)
rakeshchennupati143: one more thing i think you liked it, so mark it as brainliest, it will be helpful for me ;)
Answered by fiercespartan
2

To print a reverse of a number, we will have to convert the number into a string and then reverse the number.

________________________________________________

But before reversing the number, we also have to check whether the number is greater 1000. If it is, then we reverse it. Else, we ask for the input again.

_______________________________________________

CODE:

def check():

   num = input()

   if int(num) > 1000:

       print(f'reverse:{num[::-1]}')

   else:

       check()

check()

____________________________________________

   

Similar questions