Python Forum

Full Version: help me this code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
def arec(l, b):
return l * b
def asq(s):
return s * s
def atri(h,b):
return (h*b)/2
def acir®:
return 3.14(r*r)

print("Select operation")
print("1.Area of Rectangle")
print("2.Area of Square")
print("3.Area of Triangle")
print("4.Area of Circle")

operation = input("Enter choice (1/2/3/4):")

#Parameters

length = int(input("Enter Length: "))
breadth = int(input("Enter Breadth: "))
side = int(input("Enter Side: "))
height = int(input("Enter Height: "))
base = int(input("Enter Base: "))
radius = int(input("Enter Radius: "))
height = int(input("Enter Height: "))

if operation == '1':
print("Area","=", arec(length,breadth))

elif operation == '2':
print("Area","=", asq(side))

elif operation == '3':
print("Area","=", atri(height,base))

elif operation == '4':
print("Area","=", acir(radius))
else :
print("Invalid Input")
My problem is that when i select a specific operation like area of circle i have to enter all parameters like height breadth
And also check it for other errors
You just need to move the inputs where you get the parameters under the if/elif blocks where you make the calculations:

if operation == '1':
    length = int(input('Enter Length: '))
    breadth = int(input('Enger Breadth: '))
    print('Area =', arec(length, breadth))