Adding Chpater 2 files (packages)

This commit is contained in:
muassif
2021-01-16 15:21:52 +04:00
committed by GitHub
parent d78cf1f8e9
commit fdea0fea98
21 changed files with 212 additions and 0 deletions
@@ -0,0 +1,4 @@
from .mycalculator import add, subtract
from .myrandom import random_1d, random_2d
from .advcalc.advcalculator import sqrt, log, ln
@@ -0,0 +1 @@
#empty
@@ -0,0 +1,14 @@
# advcalculator.py with sqrt,log and ln functions
import math
def sqrt(x):
"""This function takes square root of a number"""
return math.sqrt(x)
def log(x):
"""This function returns log of base 10"""
return math.log(x,10)
def ln(x):
"""This function returns log of base 2"""
return math.log(x,2)
@@ -0,0 +1,9 @@
# mycalculator.py with add and subtract functions
def add(x, y):
"""This function adds two numbers"""
return x + y
def subtract(x, y):
"""This function subtracts two numbers"""
return x - y
@@ -0,0 +1,14 @@
# myrandom.py with default and custom random functions
import random
def random_1d():
"""This function get a random number between 0 and 9"""
return random.randint(0,9)
def random_2d():
"""This function get a random number between 10 and 99"""
return random.randint(10,99)
def get_random(lower, upper):
"""This function get a random number between lower and upper"""
return random.randint(lower,upper)