write a python script to read an integer >1000 and reverse the number..... plz answer.....
Answers
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. :)
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()
____________________________________________