1+ import math as mt
2+ print ("PyCalc : A Simple and Lightweight Calculator. Made in Python!" )
3+ print ()
4+ print ("Select a Mathematical Operation : " )
5+ print ()
6+ print ("1. Addition" )
7+ print ("2. Subtraction" )
8+ print ("3. Multiplication" )
9+ print ("4. Division" )
10+ print ("5. Exponents (x^y)" )
11+ print ("6. Square Root" )
12+ print ("7. Cube Root" )
13+ print ("8. Approximate / Rounding" )
14+ print ("9. Heron's Formula" )
15+ print ("10. Simple Interest" )
16+ print ("11. Compound Interest" )
17+ print ("12. Exit Program" )
18+ while True :
19+ print ()
20+ ch = input ("Enter choice [ 1 - 12 ] : " )
21+ print ()
22+ if ch in ('1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' , '12' ):
23+ if ch == '1' :
24+ x = float (input ("Enter first number : " ))
25+ y = float (input ("Enter second number : " ))
26+ print (x , "+" , y , "=" , (x + y ))
27+
28+ elif ch == '2' :
29+ x = float (input ("Enter first number : " ))
30+ y = float (input ("Enter second number : " ))
31+ print (x , "-" , y , "=" , (x - y ))
32+
33+ elif ch == '3' :
34+ x = float (input ("Enter first number : " ))
35+ y = float (input ("Enter second number : " ))
36+ print (x , "*" , y , "=" , (x * y ))
37+
38+ elif ch == '4' :
39+ x = float (input ("Enter first number : " ))
40+ y = float (input ("Enter second number : " ))
41+ print (x , "/" , y , "=" , (x / y ))
42+ elif ch == '5' :
43+ x = float (input ("Enter first number : " ))
44+ y = float (input ("Enter second number : " ))
45+ print (x , "^" , y , "=" , mt .pow (x , y ))
46+ elif ch == '6' :
47+ x = float (input ("Enter a number : " ))
48+ print ("Root x = " , mt .sqrt (x ))
49+ elif ch == '7' :
50+ x = float (input ("Enter a number : " ))
51+ print ("C. Root x = " , mt .cbrt (x ))
52+ elif ch == '8' :
53+ x = float (input ("Enter a number : " ))
54+ print (round (x ))
55+ elif ch == '9' :
56+ print ("NOTE: Some Calculations may print 0.0 depending on the values!" )
57+ print ()
58+ a = float (input ("Enter the first side [a] : " ))
59+ b = float (input ("Enter the second side [b] : " ))
60+ c = float (input ("Enter third side [c] : " ))
61+ s = a + b + c
62+ print ("Perimeter =" , s )
63+ s /= 2
64+ print ("s = " , s )
65+ ar = float (mt .sqrt (s * (s - a )* (s - b )* (s - c )))
66+ print ("Area = " , ar )
67+ elif ch == '10' :
68+ p = float (input ("Enter the Principal : " ))
69+ r = float (input ("Enter the Rate [ as a percentage, ex : 10 for 10% ] : " ))
70+ t = float (input ("Enter the Time [ Years ] : " ))
71+ si : float = p * r * t
72+ si /= 100
73+ print ("Simple Interest" , si )
74+ print ("Amount = " , (si + p ))
75+ elif ch == '11' :
76+ print ("Compound Interest Calculation" )
77+ print ()
78+ p = float (input ("Enter the Principal : " ))
79+ r = float (input ("Enter the Rate [ as a percentage, ex : 10 for 10% ] : " ))
80+ n = float (input ("Enter the number of times interest is compounded per year: " ))
81+ t = float (input ("Enter the Time [ Years ] : " ))
82+ x = (100 + r )/ 100
83+ a = p * mt .pow (((100 + r )/ 100 ),(n * t ))
84+ ci = a - p
85+ print ("Compound Interest =" , ci )
86+ print ("Amount = " , a )
87+ elif ch == '12' :
88+ print ()
89+ print ("Exiting Program...." )
90+ exit (0 )
91+ next_calc = input ("Do you want to do another calculation? (y/n): " )
92+ if next_calc == "n" or next_calc == "N" or next_calc == "No" or next_calc == "no" :
93+ break
94+ else :
95+ print ("Please enter a Valid Input! Restarting the Program..." )
0 commit comments