2016-10-05 13 views
-6
print ("Welcome to my Area Calculator") 
i=raw_input("Please enter the shape whose Area you want to calculate(square/rectangle/right angled triangle/rhombus/parallelogram): ") 
my_list=["square","rectangle","triangle","right angled triangle","rhombus","parallelogram"] 
if i in my_list: 
    if i=="square": 
     s=float(input("What is the side of the square: ")) 
     print "Area of the square is : ", s**2 
    elif i=="rectangle": 
     l=float(input("What is the length of the rectangle: ")) 
     b=float(input("What is the breadth of the rectangle: ")) 
     print "Area of the rectangle is : ", l*b 

    elif i=="right angled triangle": 
     base1=float(input("What is the base of the triangle: ")) 
     height1=float(input("What is the height of the triangle: ")) 
     print "Area of the triangle is : ", 0.5*base1*height1 
    elif i=="rhombus": 
     d1=float(input("What is the length of the 1st diagnol of the rhombus: ")) 
     d2=float(input("What is the length of the 2nd diagnol of the rhombus: ")) 
     print "Area of the rhombus is : ", 0.5*d1*d2 
    elif i=="parallelogram": 
     base=float(input("What is the length of 1 side of the parallelogram: ")) 
     height=float(input("What is the length of the other side: ")) 
     print "Area of the parallelogram is : ", height*base 
    print "Thank you so much for using my area calculator" 

答えて

0

が条件
ドン」としてこのブール値を持つwhileループ内のすべてのコードを入れ、boolean型変数に入れて、ユーザーを依頼するためのオプションこのブール値をtrueに初期化するのを忘れないでください

2

プログラム全体を関数にしてからwhileループ内で実行してください。

while(option != 'yes'): 
    Program() 
    userInput() 
+0

ありがとうございますが、私に例を示すことができます – amith1198

関連する問題