Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions src/hello_world_project/example_module.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,50 @@
def add_numbers(a: int, b: int) -> int:
return a + b
from datetime import datetime
def godz_dek(func):
def wrapper(*args, **kwargs):
print(f"[{datetime.now().strftime('%H:%M:%S')}]")
return func(*args, **kwargs)
return wrapper

class SimpleCalculator:
def add_numbers(self, a: float, b: float) -> float:
return a + b

def sub_numbers(self, a: float, b:float) -> float:
return a - b

def multiply_numbers(self, a: float, b: float) -> float:
return a * b

def div_numbers(self, a: float, b: float) -> float:
if(abs(b)>0.0001):
return a / b
else:
raise Exception

class ScientificCalc(SimpleCalculator):
def power_numbers(self, base, exp):
return base ** exp
def sqr_numbers(self, base):
return base ** 1/2

class FinancialCalc(SimpleCalculator):
@godz_dek
def add_numbers(self, a: float, b: float) -> float:
return a + b
@godz_dek
def sub_numbers(self, a: float, b:float) -> float:
return a - b
@godz_dek
def multiply_numbers(self, a: float, b: float) -> float:
return a * b
@godz_dek
def div_numbers(self, a: float, b: float) -> float:
if(abs(b)>0.0001):
return a / b
else:
raise Exception


# def FactoryCalculator(type: str):
# factory = {"Simple": SimpleCalculator, "Science":ScientificCalc }
# return factory[type]()
28 changes: 25 additions & 3 deletions src/hello_world_project/main.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from hello_world_project.utils import greet_user
from hello_world_project.example_module import add_numbers
#! usr/bin/python3
from utils import greet_user
import example_module

def main():
print("=== Hello World Project ===")
Expand All @@ -8,8 +9,29 @@ def main():
greeting = greet_user(name)
print(greeting)

result = add_numbers(10, 5)
calc_dict={"b":example_module.SimpleCalculator, "s":example_module.ScientificCalc, "f":example_module.FinancialCalc}
calc_s= input("Enter b for basic\n, s for scientific\n and f for financial calculator:")
calc=calc_dict[calc_s]()
while True:
if calc_s == "b":
fun_dict_1={"a":example_module.SimpleCalculator.add_numbers,"s":example_module.SimpleCalculator.sub_numbers,"m":example_module.SimpleCalculator.multiply_numbers,"d":example_module.SimpleCalculator.div_numbers}
fun_s= input("Enter a for addition, \n s for subtraction, \nm for multiplication, \nd for division")
fun=fun_dict_1[fun_s]
elif calc_s == "s":
fun_dict_2={"a":example_module.ScientificCalc.add_numbers,"s":example_module.ScientificCalc.sub_numbers,"m":example_module.ScientificCalc.multiply_numbers,"d":example_module.ScientificCalc.div_numbers,"p":example_module.ScientificCalc.power_numbers,"q":example_module.ScientificCalc.sqr_numbers}
fun_s= input("Enter a for addition, \n s for subtraction, \nm for multiplication, \nd for division, \np for power, \nq for square_root ")
fun=fun_dict_2[fun_s]
else:
fun_dict_3={"a":example_module.FinancialCalc.add_numbers,"s":example_module.FinancialCalc.sub_numbers,"m":example_module.FinancialCalc.multiply_numbers,"d":example_module.FinancialCalc.div_numbers}
fun_s= input("Enter a for addition, \n s for subtraction, \nm for multiplication, \nd for division")
fun=fun_dict_3[fun_s]
a = float(input("Enter a: "))
b = float(input("Enter b: "))
print(fun(calc,a,b))

result = example_module.SimpleCalculator().add_numbers(10, 5)
print(f"The result of adding 10 and 5 is {result}.")


if __name__ == "__main__":
main()