(Python) Write a program that inputs a three-digit positive integer from the keyboard, and then outputs the corresponding number in reverse, and outputs -1 if the input number is not a three-digit positive integer.

[Problem description]
Write a program that inputs a three-digit positive integer from the keyboard, and then outputs the corresponding number in reverse. If the input number is not a three-digit positive integer, then output -1.
【Input form】
Input a three-digit positive integer from the keyboard.
[Output format]
Output the exchanged positive integer value.
【Input sample】

356

【Example of output】

653

[Example description]
The positive integer value input from the keyboard is 356, and the ones and hundreds digits of the number are exchanged, and the result is 653. If the input positive integer is 300, the output is 3.

n = int(input())
if n<100 or n>1000:
    print("-1")
else:
    a = n // 100
    b=  n%100// 10
    c = n%10
    d=c*100+b*10+a
    print(d)

Guess you like

Origin blog.csdn.net/qq_62315940/article/details/127575616