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