因此,我一直在爲學校開發一個「AI」,並遇到了一些我不知道的東西。所以當出現錯誤時,我試圖讓它跳回到問題中,但我沒有找到答案給了我一個答案。這裏是我的代碼:如何在python中跳回幾行
# CodeOne's AI
# AI
number1 = 0
number2 = 0
symbol = 0
output = 0
import time
print ("Hello and welcome to CodeOne's miniature AI")
name = input("Enter your name \n")
print ("Well hello,",name + ".")
print ("I am ROB (Recognising Organised Robot) it's nice to meet you!")
print ("I can do many things, such as do maths equations, have small conversations, and more!")
maths = input("Do you wanna do maths? \n")
if maths == "yes" or "Yes" or "YES" or "Yeah" or "yeah" or "YEAH" or "yep" or "Yep" or "YEP":
print ("Ok, type away")
number1 = input("Input the first number \n")
symbol = input("Input your desired operation (+,-,*,/) \n")
number2 = input("Input the second number \n")
if symbol == "+":
output = (int(number1) + int(number2))
elif symbol == "-":
output = (int(number1) - int(number2))
elif symbol == "*":
output = (int(number1) * int(number2))
elif symbol == "/":
output = (int(number1)/int(number2))
else:
print ("Something went wrong, ty again")
time.sleep(5)
print (output)
else:
print ("Would you like to chat then?")`
不管你做什麼,或不使用這個(https://github.com/snoack/python-goto) – Eric
嗯......你能不能解釋一下? –
sry,我正在學習 –