summaryrefslogtreecommitdiff
path: root/projects/2/prog4.py
blob: 636cc7fdb4a916cf239aa7275b007a36ce60102f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python

# This program can calculate the area and perimeter of a square, rectangle and
# square. A text user interface (TUI) is provided as well.

print("""
Program author: mo khan
ID: 3431709
PROGRAM 4-FUNCTIONS
""")

def menu():
    print("""
    CALCULATIONS MENU

    1) AREA (SQUARE)
    2) AREA (RECTANGLE)
    3) AREA (CIRCLE)
    4) PERIMETER (SQUARE)
    5) PERIMETER (RECTANGLE)
    6) PERIMETER (CIRCLE)
    7) EXIT
    """)

    return int(input("INPUT MENU CHOICE (1,2,3,4,5,6 OR 7)? "))

def area_square():
    print("YOU HAVE CHOSEN AREA (SQUARE)")
    length = int(input("INPUT LENGTH? "))
    print("AREA IS {}".format(length*length))

def area_rectangle():
    print("YOU HAVE CHOSEN AREA (RECTANGLE)")
    width = int(input("INPUT WIDTH? "))
    length = int(input("INPUT LENGTH? "))
    print("AREA IS {}".format(length*width))

def area_circle():
    print("YOU HAVE CHOSEN AREA (CIRCLE)")
    radius = int(input("INPUT RADIUS? "))
    print("AREA IS {}".format(3.4* radius**2))

def perimeter_square():
    print("YOU HAVE CHOSEN PERIMETER (SQUARE)")
    length = int(input("INPUT LENGTH? "))
    print("PERIMETER IS {}".format(4*length))

def perimeter_rectangle():
    print("YOU HAVE CHOSEN PERIMETER (RECTANGLE)")
    width = int(input("INPUT WIDTH? "))
    length = int(input("INPUT LENGTH? "))
    print("PERIMETER IS {}".format(2*length+2*width))

def perimeter_circle():
    print("YOU HAVE CHOSEN PERIMETER (CIRCLE)")
    radius = int(input("INPUT RADIUS? "))
    print("PERIMETER IS {}".format(2*3.14*radius))

def main():
    choice = 0
    while choice != 7:
        if choice == 1:
            area_square()
        elif choice == 2:
            area_rectangle()
        elif choice == 3:
            area_circle()
        elif choice == 4:
            perimeter_square()
        elif choice == 5:
            perimeter_rectangle()
        elif choice == 6:
            perimeter_circle()
        elif choice == 7:
            exit(0)
        choice = menu();

main()