输入仅两位数字的数字:10

输入另一个整数:1

1是相反的:10

我的密码

from pcinput import getInteger


minimum_len = 2
number1 = getInteger("enter a number with only two digits: ")
input_length = int(len(str(number1)))

if input_length < minimum_len:
    print("needs to be 2 digits" )
    exit(1)
elif not isinstance(number1, int):
    print("needs to be a int")

else:
     number2 = input("enter another integer: ")

def reverse_int(number1):
    return int(str(number1)[::-1])

if number1 == number2:
    print(str(number1) + " is the reverse of "+ (str(number2 )))
else:
    print(str (number2) + " is not the reverse of " + (str(number1)))

最佳答案

您不会在任何地方调用reverse_int函数。

- if number1 == number2:
+ if number1 == reverse_int(number2):

关于python - 代码改进,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50873768/

10-12 20:25