help me this code - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: help me this code (/thread-4799.html) |
help me this code - tahseen - Sep-09-2017 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 RE: help me this code - ichabod801 - Sep-09-2017 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)) |