MCPcopy Index your code
hub / github.com/geekcomputers/Python / main

Function main

calc_area.py:4–42  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2# Program to calculate the area of - square, rectangle, circle, and triangle -
3import math as m
4def main():
5 shape = int(
6 input(
7 "Enter 1 for square, 2 for rectangle, 3 for circle, 4 for triangle, 5 for cylinder, 6 for cone, or 7 for sphere: "
8 )
9 )
10 if shape == 1:
11 side = float(input("Enter length of side: "))
12 print("Area of square = " + str(side**2))
13 elif shape == 2:
14 l = float(input("Enter length: "))
15 b = float(input("Enter breadth: "))
16 print("Area of rectangle = " + str(l * b))
17 elif shape == 3:
18 r = float(input("Enter radius: "))
19 print("Area of circle = " + str(m.pi * r * r))
20 elif shape == 4:
21 base = float(input("Enter base: "))
22 h = float(input("Enter height: "))
23 print("Area of rectangle = " + str(0.5 * base * h))
24 elif shape == 5:
25 r = float(input("Enter radius: "))
26 h = float(input("Enter height: "))
27 print("Area of cylinder = " + str(m.pow(r, 2) * h * m.pi))
28 elif shape == 6:
29 r = float(input("Enter radius: "))
30 h = float(input("Enter height: "))
31 print("Area of cone = " + str(m.pow(r, 2) * h * 1 / 3 * m.pi))
32 elif shape == 7:
33 r = float(input("Enter radius: "))
34 print("Area of sphere = " + str(m.pow(r, 3) * 4 / 3 * m.pi))
35 else:
36 print("You have selected wrong choice.")
37
38 restart = input("Would you like to calculate the area of another object? Y/N : ")
39 if restart.lower().startswith("y"):
40 main()
41 elif restart.lower().startswith("n"):
42 quit()
43
44
45main()

Callers 1

calc_area.pyFile · 0.70

Calls 1

quitFunction · 0.85

Tested by

no test coverage detected