[英]how can i make the code to start over again
hi I want this code to start from line 3 again until the if/else is finished but i dont know what to type for the (if) part to do that嗨,我希望此代码再次从第 3 行开始,直到 if/else 完成,但我不知道要为 (if) 部分键入什么来执行此操作
import math
rand1 = random.randint(999,10000)
rand2 = random.randint(999,10000)
randnum = rand1 * rand2
#if randnum == randnum[::-1]:
# print("true" , randnum)
#else:
#pass
def rev(num):
return int(num != 0) and ((num % 10) * (10**int(math.log(num, 10))) + rev(num // 10))
print ("The generated number is : " + str(randnum))
res = randnum == rev(randnum)
print(res)
if res == False :
```
You could try using the while
statement, such as:您可以尝试使用
while
语句,例如:
def rev(num):
return int(num != 0) and ((num % 10) * (10**int(math.log(num, 10))) + rev(num // 10))
while res != True: # or any logic that makes sense to your problem
rand1 = random.randint(999,10000)
rand2 = random.randint(999,10000)
randnum = rand1 * rand2
res = randnum == rev(randnum)
print(res)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.