|
1 | 1 | from math import pi |
2 | 2 |
|
3 | 3 | try: |
4 | | - maincmd = int(input(""" |
5 | | -Enter 1 for Matrix |
6 | | -Enter 2 for Normal Calculations |
7 | | -Enter 3 for Area and Perimeter |
8 | | -Enter 4 for Circles |
9 | | ->>> """) |
| 4 | + maincmd = int(input(""" |
| 5 | + Enter 1 for Matrix |
| 6 | + Enter 2 for Normal Calculations |
| 7 | + Enter 3 for Area and Perimeter |
| 8 | + Enter 4 for Circles |
| 9 | + >>> """)) |
10 | 10 | except ValueError: |
11 | | - print("You have entered an invalid input. Please try again.") |
| 11 | + print("You have entered an invalid input. Please try again.") |
12 | 12 | else: |
13 | | - print() |
14 | | -if maincmd == 1: |
15 | | - try: |
| 13 | + print() |
| 14 | + if maincmd == 1: |
| 15 | + try: |
16 | 16 | cmd = int(input(""" |
17 | | - Enter 1 for Addition of Two 2x2 Matrix |
18 | | - >>> """)) |
| 17 | + Enter 1 for Additon of 2x2 Matrix |
| 18 | + >>> """)) |
19 | 19 | except ValueError: |
20 | 20 | print("You have entered an invalid input. Please try again.") |
21 | 21 | else: |
22 | | - print() |
23 | | - elif cmd == 1: |
24 | | - n11 = float(input("Enter the element of 1st column and 1st row of 1st matrix: ")) |
25 | | - n12 = float(input("Enter the element of 2nd column and 1st row of 1st matrix: ")) |
26 | | - n21 = float(input("Enter the element of 1st column and 2nd row of 1st matrix: ")) |
27 | | - n22 = float(input("Enter the element of 2nd column and 2nd row of 1st matrix: ")) |
28 | | - m11 = float(input("Enter the element of 1st column and 1st row of 2nd matrix: ")) |
29 | | - m12 = float(input("Enter the element of 2nd column and 1st row of 2nd matrix: ")) |
30 | | - m21 = float(input("Enter the element of 1st column and 2nd row of 2nd matrix: ")) |
31 | | - m22 = float(input("Enter the element of 2nd column and 2nd row of 2nd matrix: ")) |
32 | | - X = [[n11, n12], [n21, n22]] |
33 | | - Y = [[m11, m12], [m21, m22]] |
34 | | - result = [[0, 0], [0, 0]] |
35 | | - # Iterate Through Rows |
36 | | - for i in range(len(X)): |
37 | | - # iterate through columns |
38 | | - for j in range(len(X[0])): |
39 | | - # noinspection PyTypeChecker |
40 | | - result[i][j] = X[i][j] + Y[i][j] |
41 | | - for r in result: |
42 | | - print(r) |
43 | | -elif maincmd == 2: |
44 | | - try: |
45 | | - cmd = int(input(""" |
46 | | - Enter 1 for Area of Square |
47 | | - Enter 2 for Perimeter of Square |
48 | | - Enter 3 for Area of Rectangle |
49 | | - Enter 4 for Perimeter of Rectangle |
50 | | - Enter 5 for Area of Circle |
51 | | - Enter 6 for Diameter of Circle |
52 | | - Enter 7 for Circumference of Circle |
53 | | - Enter 8 for Area of Triangle |
54 | | - Enter 9 for Perimeter of Triangle |
55 | | - Enter 10 for Area of Trapezium |
56 | | - >>> """)) |
57 | | - except ValueError: |
58 | | - print("You have entered an invalid input. Please try again.") |
59 | | - else: |
60 | | - print() |
61 | | - if cmd in [1, 2]: |
62 | | - length = float(input("Enter length of sides of Square: ")) |
63 | | - if cmd == 1: |
64 | | - print(length * length) |
65 | | - else: |
66 | | - print(4 * length) |
67 | | - elif cmd in [3, 4]: |
68 | | - length = float(input("Enter length of Rectangle: ")) |
69 | | - breath = float(input("Enter width of Rectangle: ")) |
70 | | - if cmd == 3: |
71 | | - print(length * breath) |
72 | | - else: |
73 | | - print(2 * (length + breath)) |
74 | | - elif cmd in [5, 6, 7]: |
75 | | - radius = float(input("Enter radius of circle: ")) |
76 | | - pichoice = input("What format of Pi would you want to use? 22/7, 3.14 or Calculator Pi? Enter Here: ") |
77 | | - if cmd == 5: |
78 | | - if pichoice == 22/7: |
79 | | - print(22 / 7 * (radius * radius)) |
80 | | - elif pichoice == 3.14: |
81 | | - print(3.14 * (radius * radius)) |
82 | | - else: |
83 | | - print(pi * (radius * radius)) |
84 | | - elif cmd == 6: |
85 | | - print(2 * radius) |
86 | | - else: |
87 | | - if pichoice == 22/7: |
88 | | - print(22 / 7 * (radius * 2)) |
89 | | - if pichoice == 3.14: |
90 | | - print(3.14 * (radius * 2)) |
91 | | - else: |
92 | | - print(pi * (radius * 2)) |
93 | | - elif cmd == 8: |
94 | | - base = float(input("Enter base of triangle: ")) |
95 | | - height = float(input("Enter height of triangle: ")) |
96 | | - print(0.5 * base * height) |
97 | | - elif cmd == 9: |
98 | | - side = float(input("Enter side of triangle: ")) |
99 | | - side2 = float(input("Enter second side of triangle: ")) |
100 | | - side3 = float(input("Enter third side of triangle: ")) |
101 | | - print(side + side2 + side3) |
102 | | - elif cmd == 10: |
103 | | - a = float(input("Enter base of trapezium: ")) |
104 | | - b = float(input("Enter top length of trapezium: ")) |
105 | | - height = float(input("Enter height of trapezium: ")) |
106 | | - if cmd == 10: |
107 | | - print(0.5 * (a + b) * height) |
108 | | - else: |
109 | | - width = float(input("Enter width of trapezium: ")) |
110 | | - print((0.5 * (a + b) * height) * width) |
111 | | - else: |
112 | | - try: |
113 | | - cmd = int(input(""" |
114 | | - Enter 12 for Usual Addition Calculations |
115 | | - Enter 13 for Usual Subtraction Calculations |
116 | | - Enter 14 for Usual Multiplication Calculations |
117 | | - Enter 15 for Usual Division Calculations |
118 | | - >>> """)) |
119 | | - except ValueError: |
120 | | - print("You have entered an invalid input. Please try again.") |
121 | | - else: |
122 | | - elif cmd in [12, 13, 14, 15]: |
123 | | - if cmd == 12: |
124 | | - num1 = float(input("Enter First Number: ")) |
125 | | - num2 = float(input("Enter Second Number: ")) |
126 | | - print(num1 + num2) |
127 | | - elif cmd == 13: |
128 | | - num1 = float(input("Enter First Number: ")) |
129 | | - num2 = float(input("Enter Second Number: ")) |
130 | | - print(num1 - num2) |
131 | | - elif cmd == 14: |
132 | | - num1 = float(input("Enter First Number: ")) |
133 | | - num2 = float(input("Enter Second Number: ")) |
134 | | - print(num1 * num2) |
135 | | - else: |
136 | | - num1 = float(input("Enter First Number: ")) |
137 | | - num2 = float(input("Enter Second Number: ")) |
138 | | - print(num1 / num2) |
139 | | -else: |
140 | | - print("You have entered in an invalid input. Please try again.") |
| 22 | + print() |
| 23 | + if cmd == 1: |
| 24 | + n11 = float(input("Enter the element of the 1st column and 1st row of the 1st matrix: ")) |
| 25 | + n12 = float(input("Enter the element of the 2nd column and the 1st row of the 1st matrix: ")) |
| 26 | + n21 = float(input("Enter the element of the 1st column and 2nd row of the 1st matrix: ")) |
| 27 | + n22 = float(input("Enter the elemrnt of the 2nd column and the 2nd row of the 1st matrix: ")) |
| 28 | + m11 = float(input("Enter the element of the 1st column and 1st row of 2nd matrix: ")) |
| 29 | + m12 = float(input("Enter the element of the 2nd column and 1st row of 2nd matrix: ")) |
| 30 | + m21 = float(input("Enter the element of the 2nd column and 1st row of 2nd matrix: ")) |
| 31 | + m22 = float(input("Enter the element of the 2nd column and 2nd row of 2nd matrix: ")) |
| 32 | + X = [[n11, n12], [n21, n12]] |
| 33 | + Y = [[m11, m12], [m21, m22]] |
| 34 | + result = [[0, 0], [0, 0]] |
| 35 | + for i in range(len(X)): |
| 36 | + for j in range(len(X[0])): |
| 37 | + result[i][j] = X[i][j] + Y[i][j] |
| 38 | + for r in result: |
| 39 | + print(r) |
| 40 | + elif maincmd == 2: |
| 41 | + try: |
| 42 | + cmd = int(input(""" |
| 43 | + Enter 1 for Addition |
| 44 | + Enter 2 for Subtraction |
| 45 | + Enter 3 for Multiplication |
| 46 | + Enter 4 for Division |
| 47 | + >>> """)) |
| 48 | + except ValueError: |
| 49 | + print("You have entered an invalid input. Please try again.") |
| 50 | + else: |
| 51 | + print() |
| 52 | + if cmd in [1, 2, 3, 4]: |
| 53 | + num1 = float(input("Enter the First Number: ")) |
| 54 | + num2 = float(input("Enter the Second Number: ")) |
| 55 | + if cmd == 1: |
| 56 | + print(num1 + num2) |
| 57 | + elif cmd == 2: |
| 58 | + print(num1 - num2) |
| 59 | + elif cmd == 3: |
| 60 | + print(num1 * num2) |
| 61 | + else: |
| 62 | + print(num1 / num2) |
| 63 | + elif maincmd == 3: |
| 64 | + try: |
| 65 | + cmd = int(input(""" |
| 66 | + Enter 1 for Area of Square |
| 67 | + Enter 2 for Perimeter of Square |
| 68 | + Enter 3 for Area of Rectangle |
| 69 | + Enter 4 for Perimeter of Rectangle |
| 70 | + Enter 5 for Area of Triangle |
| 71 | + Enter 6 for Perimeter of Triangle |
| 72 | + Enter 7 for Area of Trapezium |
| 73 | + >>> """)) |
| 74 | + except ValueError: |
| 75 | + print("You have entered an invalid input. Please try again.") |
| 76 | + else: |
| 77 | + print() |
| 78 | + if cmd in [1, 2]: |
| 79 | + length = float(input("Enter the length of a side of the square: ")) |
| 80 | + if cmd == 1: |
| 81 | + print(length * length) |
| 82 | + else: |
| 83 | + print(length * 4) |
| 84 | + elif cmd in [3, 4]: |
| 85 | + length = float(input("Enter the length of a side of the rectangle: ")) |
| 86 | + breath = float(input("Enter the breath of a side of the rectangle: ")) |
| 87 | + if cmd == 3: |
| 88 | + print(length * breath) |
| 89 | + else: |
| 90 | + print(2 * (length + breath)) |
| 91 | + elif cmd == 5: |
| 92 | + base = float(input("Enter Base of Triangle: ")) |
| 93 | + height = float(input("Enter Height of Triangle: ")) |
| 94 | + print(0.5 * base * height) |
| 95 | + elif cmd == 6: |
| 96 | + side1 = float(input("Enter 1st side of triangle: ")) |
| 97 | + side2 = float(input("Enter the 2nd side of triangle: ")) |
| 98 | + side3 = float(input("Enter the 3rd side of triangle: ")) |
| 99 | + print(side1 + side2 + side3) |
| 100 | + else: |
| 101 | + a = float(input("Enter 1st side of Trapezium: ")) |
| 102 | + b = float(input("Enter 2nd side of Trapezium: ")) |
| 103 | + height = float(input("Enter height of Trapezium: ")) |
| 104 | + print(0.5 * a * b * height) |
| 105 | + elif cmd == 4: |
| 106 | + try: |
| 107 | + cmd = int(input(""" |
| 108 | + Enter 1 for Area of Circle |
| 109 | + Enter 2 for Circumference of Circle |
| 110 | + Enter 3 for Diameter of Circle |
| 111 | + >>> """)) |
| 112 | + except ValueError: |
| 113 | + print("You have entered an invalid input. Please try again.") |
| 114 | + else: |
| 115 | + if cmd in [1, 2]: |
| 116 | + pichoice = input("Please enter prefered choice of Pi: ") |
| 117 | + radius = float(input("Enter the Radius of The Circle: ")) |
| 118 | + if pichoice == 3.14: |
| 119 | + if cmd == 1: |
| 120 | + print(3.14 * radius * radius) |
| 121 | + else: |
| 122 | + diameter = radius * 2 |
| 123 | + print(3.14 * diameter) |
| 124 | + elif pichoice == 22 / 7: |
| 125 | + if cmd == 1: |
| 126 | + print(22 / 7 * radius * radius) |
| 127 | + else: |
| 128 | + diameter = radius * 2 |
| 129 | + print(22 / 7 * diameter) |
| 130 | + else: |
| 131 | + if cmd == 1: |
| 132 | + print(pi * radius * radius) |
| 133 | + else: |
| 134 | + diameter = radius * 2 |
| 135 | + print(pi * diameter) |
| 136 | + else: |
| 137 | + radius = float(input("Enter the Radius of Circle: ")) |
| 138 | + print(radius * 2) |
| 139 | + |
0 commit comments