python跳回循环开始位置_如何回到python中循环的开始?
我的代碼:b="y"
ol=[]
#operations list
OPERATIONS = ["-", "+", "*", "/"]
op = input ("Please enter your first calculation\n")
while b=="y":
ops = op.split(" ")
#add arguments to list
for x in ops:
ol+=x
if ol[1] in OPERATIONS:
#make sure operator is an operator
print()
#make sure not dividing by zero
if ol[1] == "/" and ol[2] == "0":
print("Error")
b = input("Would you like to do another calculation (y/n)?\n")
if b == "y":
op = input("Please enter your calculation:\n")
continue
else:
break
else:
n1 = float(ol[0])
n2 = float(ol[2])
#calculations done here
if ol[1] == '-':
calc = n1-n2
if ol[1] == '+':
calc = n1+n2
if ol[1] == '/':
calc = n1/n2
if ol[1] == '*':
calc = n1*n2
print("Result: " + str(calc))
b = input("Would you like to do another calculation (y/n)?\n")
if b == "y":
op = input("Please enter your calculation:\n")
continue
else:
break
else:
print("Error")
如何確保程序將新操作帶到循環的開始,而不是繼續打印原始計算?在
總結
以上是生活随笔為你收集整理的python跳回循环开始位置_如何回到python中循环的开始?的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: git 生成多个patch_如何用git
- 下一篇: python集合是有序的吗_python
