gpt4 book ai didi

python - 代码改进

转载 作者:太空宇宙 更新时间:2023-11-04 09:43:17 25 4
gpt4 key购买 nike

请输入一个只有两位数的数字: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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com