我已經做了約4周的編程現在。愛它到目前爲止。但是我一直在寫這段代碼。這是關於形狀的區域。我試圖看看這裏,看到一些線程,但它沒有幫助。 當我不想要它時,它會保持循環。保持循環。嘗試其他線程,沒有工作
更新時間:
#Area of shapes
shape=[]
choice= None
while choice !="0":
print (
"""
Choices:
0. Exit
1.Square
2.Rectangle
3.Triangle
4.Trapezium
"""
)
choice = input ("Choice\n")
print()
#Exit
if choice != "0":
print ("Incorrect, please try again")
#Square
elif choice in ["1", "Square"]:
square1=int(input("Please input the side of the square\n"))
print ("The area of the square is", square1*4,)
#Rectangle
elif choice in ["1", "Rectangle"]:
rectangle1 = int(input ("Please input the side of the reactanglezn"))
rectangle2 = int(input ("Please input the other side of the reactangle\n"))
arearect== rectangle1*rectangle2
print ("The area of the rectangle is of", arearect)
#Triangle
elif choice in ["1", "Triangle"]:
triangle1 = int(input ("Please input the base of the triangle"))
triangle2 = int(input ("Please input the height of the triangle"))
areatri =0.5*triangle1*triangle2
print ("The area of the triangle is", areatri)
#Trapezium
elif choice in ["1", "Trapezium"]:
trapezium1 = int(input ("Please input the side A of the trapezium"))
trapezium2= int(input ("Please input the side B of the trapezium"))
trapezium3= int(input ("Please input the height of the trapezium"))
areatrap= trapezium1*trapezium2/2*trapezium3
print ("The area of the trapezium is", areatrap)
else:
print ("Invalid Choice")
縮進是錯誤的。您必須在'while'下面至少縮進一行:'choice = input()'。 – Boldewyn
您能澄清問題中顯示的縮進是否與您的實際代碼相匹配。另外,你能準確地展示發生了什麼?輸入和麪積計算是永久重複的,還是隻是初始提示? – Blckknght
永遠重複@Blckknght –