Created
January 24, 2022 07:39
-
-
Save WizzyGeek/5865edb30236831391658fbe7576ab6e to your computer and use it in GitHub Desktop.
my first calculator thingy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import decimal | |
# version check | |
import sys | |
from decimal import Decimal | |
if sys.version_info[0] != 3: | |
try: | |
print("This script requires Python 3") | |
except SyntaxError as err: | |
raise err | |
pi = Decimal("3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989") | |
def set_prec(): | |
try: | |
context = decimal.Context( | |
prec=int(input("precesion(no.of digits required):- ")) | |
) | |
decimal.setcontext(context) | |
except ValueError: | |
try: | |
print("enter a natural no.!") | |
context = decimal.Context( | |
prec=int(input("precesion(no.of digits required):- ")) | |
) | |
decimal.setcontext(context) | |
except ValueError: | |
print("precision has been set to 500") | |
context = decimal.Context(prec=500) | |
decimal.setcontext(context) | |
except OverflowError: | |
print("precision has been set to 500") | |
context = decimal.Context(prec=500) | |
decimal.setcontext(context) | |
except OverflowError: | |
try: | |
print("integer too large") | |
context = decimal.Context( | |
prec=int(input("precesion(no.of digits required):- ")) | |
) | |
decimal.setcontext(context) | |
except ValueError: | |
print("not a natural no. - precision has been set to 500") | |
context = decimal.Context(prec=500) | |
decimal.setcontext(context) | |
except OverflowError: | |
print("integer too big - precision has been set to 500") | |
context = decimal.Context(prec=500) | |
decimal.setcontext(context) | |
class op: | |
@staticmethod | |
def add(): | |
"""a function that prompts the user to add complex no.s""" | |
set_prec() | |
try: | |
x = Decimal(input("value 1: ")) | |
y = Decimal(input("value 2: ")) | |
ans = x + y | |
print(Decimal(ans)) | |
except ValueError: | |
print("invalid character in input") | |
x = Decimal(input("value 1: ")) | |
y = Decimal(input("value 2: ")) | |
ans = x + y | |
print(Decimal(ans)) | |
@staticmethod | |
def sub(): | |
set_prec() | |
try: | |
x = Decimal(input("value 1: ")) | |
y = Decimal(input("value 2: ")) | |
ans = x - y | |
print(Decimal(ans)) | |
except ValueError: | |
print("invalid character in input") | |
x = Decimal(input("value 1: ")) | |
y = Decimal(input("value 2: ")) | |
ans = x - y | |
print(Decimal(ans)) | |
@staticmethod | |
def multi(): | |
set_prec() | |
try: | |
x = Decimal(input("value 1: ")) | |
y = Decimal(input("value 2: ")) | |
ans = x * y | |
print(Decimal(ans)) | |
except ValueError: | |
print("invalid character in input") | |
@staticmethod | |
def div(): | |
try: | |
set_prec() | |
x = Decimal(input("value 1: ")) | |
y = Decimal(input("value 2: ")) | |
ans = x / y | |
print(Decimal(ans)) | |
except ValueError: | |
print("invalid character in input") | |
except ZeroDivisionError: | |
print("Can't divide by Zero") | |
class con(): | |
@staticmethod | |
def c2j(): | |
set_prec() | |
try: | |
x = Decimal(input("calories: ")) | |
ans = Decimal(x * 4.18400) | |
print(ans) | |
except ValueError: | |
print("invalid character in input") | |
@staticmethod | |
def j2c(): | |
set_prec() | |
try: | |
c = Decimal('4.18400') | |
x = Decimal(input("joules: ")) | |
ans = Decimal(x / c) | |
print(ans) | |
except ValueError: | |
print("invalid character in input") | |
c = Decimal('4.18400') | |
x = Decimal(input("joules: ")) | |
ans = Decimal(x / c) | |
print(ans) | |
class vol(): | |
@staticmethod | |
def cube(): | |
set_prec() | |
try: | |
x = Decimal(input("side / val: ")) | |
print(x * x * x + " units") | |
except ValueError: | |
print("invalid character in input") | |
x = Decimal(input("side / val: ")) | |
print(x * x * x + " units") | |
@staticmethod | |
def cuboid(): | |
set_prec() | |
try: | |
l = Decimal(input("lenght: ")) | |
h = Decimal(input("height: ")) | |
b = Decimal(input("breadth: ")) | |
ans = l * b * h | |
print(Decimal(ans)) | |
except ValueError: | |
print("invalid character in input") | |
l = Decimal(input("lenght: ")) | |
h = Decimal(input("height: ")) | |
b = Decimal(input("breadth: ")) | |
ans = l * b * h | |
print(Decimal(ans)) | |
@staticmethod | |
def cyl(): | |
set_prec() | |
try: | |
r = Decimal(input("radius: ")) | |
h = Decimal(input("height: ")) | |
ans = pi * r * r * h | |
print(Decimal(ans)) | |
except ValueError: | |
print("invalid character in input") | |
r = Decimal(input("radius: ")) | |
h = Decimal(input("height: ")) | |
ans = pi * r * r * h | |
print(Decimal(ans)) | |
class ar(): | |
@staticmethod | |
def rect(): | |
set_prec() | |
try: | |
l = Decimal(input("lenght: ")) | |
b = Decimal(input("breadth: ")) | |
ans = l * b | |
print(Decimal(ans)) | |
except ValueError: | |
print("invalid character in input") | |
return l * b | |
@staticmethod | |
def sq(): | |
set_prec() | |
try: | |
s = Decimal(input("side: ")) | |
ans = s * s * 2 | |
print(Decimal(ans)) | |
except ValueError: | |
print("invalid character in input") | |
@staticmethod | |
def circle(): | |
set_prec() | |
try: | |
r = Decimal(input("radius: ")) | |
ans = pi * r * r | |
print(Decimal(ans)) | |
except ValueError: | |
print("invalid character in input") | |
class sa(): | |
@staticmethod | |
def cube(): | |
set_prec() | |
# surface area of cube | |
try: | |
s = Decimal(input("side: ")) | |
ans = s * s * 6 | |
print(Decimal(ans)) | |
except ValueError: | |
print("invalid character in input") | |
@staticmethod | |
def cyl(): | |
# t.s.a | |
set_prec() | |
try: | |
r = Decimal(input("radius: ")) | |
h = Decimal(input("height: ")) | |
ans = 2 * pi * r * (r + h) | |
print(Decimal(ans)) | |
except ValueError: | |
print("invalid character in input") | |
@staticmethod | |
def cuboid(): | |
set_prec() | |
try: | |
l = Decimal(input("lenght: ")) | |
h = Decimal(input("height: ")) | |
b = Decimal(input("breadth: ")) | |
ans = 2 * (l * b) + 2 * (l * h) + 2 * (b * h) | |
print(Decimal(ans)) | |
except ValueError: | |
print("invalid character in input") | |
class lsa(): | |
@staticmethod | |
def cyl(): | |
set_prec() | |
try: | |
r = Decimal(input("radius: ")) | |
h = Decimal(input("height: ")) | |
ans = 2 * pi * r * h | |
print(Decimal(ans)) | |
except ValueError: | |
print("invalid character in input") | |
@staticmethod | |
def cube(): | |
set_prec() | |
try: | |
s = Decimal(input("side: ")) | |
ans = Decimal(s * s) * 4 | |
print(Decimal(ans)) | |
except ValueError: | |
print("invalid character in input") | |
@staticmethod | |
def cuboid(): | |
set_prec() | |
try: | |
l = Decimal(input("lenght: ")) | |
h = Decimal(input("height: ")) | |
b = Decimal(input("breadth: ")) | |
ans = 2 * (l * b) + 2 * (l * h) | |
print(Decimal(ans)) | |
except ValueError: | |
print("invalid character in input") | |
#interactive class end | |
# class end | |
class Pop: | |
@staticmethod | |
def add(x, y): | |
return x + y | |
@staticmethod | |
def sub(x, y): | |
return x - y | |
@staticmethod | |
def multi(x, y): | |
return x * y | |
@staticmethod | |
def div(x, y): | |
return x / y | |
class Pcon(): | |
@staticmethod | |
def c2j(x): | |
return x * 4.18400 | |
@staticmethod | |
def j2c(x): | |
return x / 4.18400 | |
class Pvol(): | |
@staticmethod | |
def cube(x): | |
return x ** 3 | |
@staticmethod | |
def cuboid(l, b, h): | |
ans = l * b * h | |
return ans | |
@staticmethod | |
def cyl(r, h): | |
ans = pi * r * r * h | |
return ans | |
class Par(): | |
@staticmethod | |
def rect(l, b): | |
ans = l * b | |
return ans | |
@staticmethod | |
def sq(s): | |
ans = s ** 2 | |
return ans | |
class Psa(): | |
@staticmethod | |
def cube(s): | |
# surface area of cube | |
ans = s * s * 6 | |
return ans | |
@staticmethod | |
def cylinder(r, h): | |
# t.s.a | |
ans = 2 * pi * r * (r + h) | |
return ans | |
class Plsa(): | |
@staticmethod | |
def cyl(r, h): | |
ans = 2 * pi * r * h | |
return ans | |
@staticmethod | |
def cube(s): | |
ans = Decimal(s ** 2) * 4 | |
return ans | |
@staticmethod | |
def cuboid(l, b, h): | |
ans = 2 * (l * b) + 2 * (l * h) | |
return ans | |
# class end | |
#---------------------------------------------------- END OF FILE ----------------------------------------------------# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment