gpt4 book ai didi

python - 更改 while() 循环内的操作顺序

转载 作者:太空宇宙 更新时间:2023-11-04 09:10:22 27 4
gpt4 key购买 nike

我是 python 新手,目前正在上课,我的程序如下所示:

if choice=="1":
def addition():
print("You are doing addition. X+Y=Z")
X = int(input("Enter X:"))
Y = int(input("Enter Y:"))
sum = X + Y
print ("your total is:")
print (sum)


Well = "y"
while Well == "y":
again = input("Would you like to go again? (y/n)")
if again == "y":
addition()
if again == "n":
project()
else:
print("sorry re-enter choice")

在显示实际添加部分之前,它询问我是否要再去一次。我该如何解决?感谢您的帮助:)

最佳答案

有很多方法,但您可以像这样将 addition() 函数放在顶部:

Well = "y"
while Well == "y":
addition()
again = input("Would you like to go again? (y/n)")
if again == "n":
project()
if again not in ("n", "y"):
print("sorry re-enter choice")

关于python - 更改 while() 循环内的操作顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16007009/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com