简体   繁体   English

我怎样才能让代码重新开始

[英]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.

相关问题 如何让python代码一遍又一遍地运行? - How can I get a python code to run over and over again? 如何根据变量使循环开始,中断和重新开始? - How to make loops start, break and start over again according to a variable? 我如何停止其他循环并让它重新开始? - How do i stop else looping and make it all start all over again? 我怎样才能使这个 python 脚本连续/一遍又一遍地运行 - how can i make this python script continuously/ run over and over again 如何在计时器后重新开始循环? - How can I make my loop start over after a timer? 如何使代码从列表中选择一项,将其打印并一次又一次重复该过程? - How can I make the code choose one of the items from the list, print it and repeat the process again and again? 如何重复执行某个命令? - How do I make an certain command repeat over and over again? 如何让我的代码(一辆汽车在屏幕上行驶)重复并从头开始? - How do I make my code (a car driving across the screen) repeat and start at the beginning again? 如何使列号在已排序的 pandas 数据帧中再次从零开始 - How can I make the column numbers change to start at zero again in a pandas data frame that has been sorted 运行代码后,我的 while 循环回到顶部。我怎样才能让它在 'again; 之后再次启动? - My while loop goes back to the top after running the code.How Can I make it that it starts again after the 'again;?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM