我试图弄清楚如何让 Python 回到代码的顶部。在 SmallBasic 中,您可以
start:
    textwindow.writeline("Poo")
    goto start
但我不知道你是如何在 Python 中做到这一点的:/ 有什么想法吗?
我试图循环的代码是这个
#Alan's Toolkit for conversions
def start() :
    print ("Welcome to the converter toolkit made by Alan.")
    op = input ("Please input what operation you wish to perform. 1 for Fahrenheit to Celsius, 2 for meters to centimetres and 3 for megabytes to gigabytes")
if op == "1":
    f1 = input ("Please enter your fahrenheit temperature: ")
    f1 = int(f1)
    a1 = (f1 - 32) / 1.8
    a1 = str(a1)
    print (a1+" celsius") 
elif op == "2":
    m1 = input ("Please input your the amount of meters you wish to convert: ")
    m1 = int(m1)
    m2 = (m1 * 100)
    m2 = str(m2)
    print (m2+" m")
if op == "3":
    mb1 = input ("Please input the amount of megabytes you want to convert")
    mb1 = int(mb1)
    mb2 = (mb1 / 1024)
    mb3 = (mb2 / 1024)
    mb3 = str(mb3)
    print (mb3+" GB")
else:
    print ("Sorry, that was an invalid command!")
start()
所以基本上,当用户完成转换时,我希望它循环回到顶部。我仍然无法将您的循环示例付诸实践,因为每次我使用 def 函数进行循环时,它都会说未定义“op”。