Question: (Ignore my notes) How can I change this code to make it a function? Such as; def areaRectangle.... I tried it and it doesn't work
(Ignore my notes)
How can I change this code to make it a function? Such as; def areaRectangle....
I tried it and it doesn't work out. Please help! Thanks.
-----
#Ryan Snyder, Period 6A, 11/15, Assignment 5.1area #(fix above) import math #For Area of Rectangle; user is asked to enter base and height then is calculated print("** Area of Rectangle **") def areaRectangle(rBase, rHeight): rBase = float(input("Please enter the base of the rectangle ::")) rHeight = float(input("Please enter the height of the rectangle ::")) rArea = rBase * rHeight #Rectangle formula with variables print("") #This is used a lot in my assignments just for organization of the output. print("The area of the rectangle is ::", rArea) #For Area of triangle; user is asked to enter base and height then formula is used below print("") print("** Area of Triangle **") def areaTriangle(tBase, tHeight): tBase = float(input("Please enter the base of the triangle ::")) tHeight = float(input("Please enter the height of the triangle ::")) print("") tArea = tBase * tHeight // 2 #Here is the formula for the area of a triangle print("The area of the triangle is ::", tArea) print("") #For Area of Circle; followed by equation/formula below print("** Area of a Circle **") def main(): def areaCircle(cArea): cRadius = float(input("Please enter the radius of the circle ::")) print("") cArea = math.pi * cRadius**2 #here is the formula followed by the answer print("The area of the circle is :: ""%.4f" % cArea) #four decimal points main() Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
