欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

python跳回循环开始位置_如何回到python中循环的开始?

发布时间:2023/12/18 python 33 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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中循环的开始?的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。