main
1#!/usr/bin/env python
2
3# This program can calculate the area and perimeter of a square, rectangle and
4# square. A text user interface (TUI) is provided as well.
5
6print("""
7Program author: mo khan
8ID: 3431709
9PROGRAM 4-FUNCTIONS
10""")
11
12def menu():
13 print("""
14 CALCULATIONS MENU
15
16 1) AREA (SQUARE)
17 2) AREA (RECTANGLE)
18 3) AREA (CIRCLE)
19 4) PERIMETER (SQUARE)
20 5) PERIMETER (RECTANGLE)
21 6) PERIMETER (CIRCLE)
22 7) EXIT
23 """)
24
25 return int(input("INPUT MENU CHOICE (1,2,3,4,5,6 OR 7)? "))
26
27def area_square():
28 print("YOU HAVE CHOSEN AREA (SQUARE)")
29 length = int(input("INPUT LENGTH? "))
30 print("AREA IS {}".format(length*length))
31
32def area_rectangle():
33 print("YOU HAVE CHOSEN AREA (RECTANGLE)")
34 width = int(input("INPUT WIDTH? "))
35 length = int(input("INPUT LENGTH? "))
36 print("AREA IS {}".format(length*width))
37
38def area_circle():
39 print("YOU HAVE CHOSEN AREA (CIRCLE)")
40 radius = int(input("INPUT RADIUS? "))
41 print("AREA IS {}".format(3.4* radius**2))
42
43def perimeter_square():
44 print("YOU HAVE CHOSEN PERIMETER (SQUARE)")
45 length = int(input("INPUT LENGTH? "))
46 print("PERIMETER IS {}".format(4*length))
47
48def perimeter_rectangle():
49 print("YOU HAVE CHOSEN PERIMETER (RECTANGLE)")
50 width = int(input("INPUT WIDTH? "))
51 length = int(input("INPUT LENGTH? "))
52 print("PERIMETER IS {}".format(2*length+2*width))
53
54def perimeter_circle():
55 print("YOU HAVE CHOSEN PERIMETER (CIRCLE)")
56 radius = int(input("INPUT RADIUS? "))
57 print("PERIMETER IS {}".format(2*3.14*radius))
58
59def main():
60 choice = 0
61 while choice != 7:
62 if choice == 1:
63 area_square()
64 elif choice == 2:
65 area_rectangle()
66 elif choice == 3:
67 area_circle()
68 elif choice == 4:
69 perimeter_square()
70 elif choice == 5:
71 perimeter_rectangle()
72 elif choice == 6:
73 perimeter_circle()
74 elif choice == 7:
75 exit(0)
76 choice = menu();
77
78main()