尝试将此代码添加到我的Python程序的末尾,以询问用户是要重新启动该程序还是结束该程序。如果我说“是”,程序将再次循环,但不会询问用户是否要在结束后重新启动。我想念什么?
while Cont != "n" and Cont != "y":
Cont=input("Do you want to draw another shape? (y/n): ")
#Summary
if Cont == "n":
print("\n")
print("Here is a summary of the shapes drawn:\n1)Horizontal Line",Horizontal_Line,"\n2)Vertical Line",Vertical_Line,"\n3)Rectangle",Rectangle,"\n4)Right Triangle",Right_Triangle,"\n5)Isosceles Triangle",Isosceles_Triangle,"\n6)???",Trapezoid,)
break
答案 0 :(得分:0)
您的while
循环评估是错误的。 Cont
变量将永远不会同时存储y
和n
,这就是为什么程序永远不会到达循环的原因。
您可以先询问,然后根据该决定进行评估。
while True:
cont=input("Do you want to draw another shape? (y/n): ")
if Cont == "n":
print("\n")
print("Here is a summary of the shapes drawn:\n1)Horizontal Line",Horizontal_Line,"\n2)Vertical Line",Vertical_Line,"\n3)Rectangle",Rectangle,"\n4)Right Triangle",Right_Triangle,"\n5)Isosceles Triangle",Isosceles_Triangle,"\n6)???",Trapezoid,)
break