Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help me this code
#1
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
Reply
#2
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))
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020