First Commit
This commit is contained in:
139
day3/excersise.py
Normal file
139
day3/excersise.py
Normal file
@@ -0,0 +1,139 @@
|
||||
age:int = 20
|
||||
height: float = 1.76
|
||||
complexNum: complex = 1 + 3j
|
||||
|
||||
def areaOfTriangle(base:float, height: float) -> float:
|
||||
return (0.5*base*height)
|
||||
|
||||
def sideOfTriangle(a: int, b: int, c: int) -> int:
|
||||
return (a+b+c)
|
||||
|
||||
def dataOfRectangle(length: float, width: float) -> [float, float]:
|
||||
return [length*width, (2*(lenght+width))]
|
||||
|
||||
def dataOfCircle(radius:float) -> [float, float]:
|
||||
pi = 3.14
|
||||
return [pi * (r**2), (2*pi)*(radius*2)]
|
||||
|
||||
def slopeOne(a:float, b:float) -> (float,float,float):
|
||||
slope = a
|
||||
y_inter= b
|
||||
x_inter= -b/a if a != 0 else None
|
||||
return (slope, x_inter, y_inter)
|
||||
|
||||
def slopeBtwePnt(p1:float, p2:float) -> float:
|
||||
x1, y1 = p1
|
||||
x2, y2 = p2
|
||||
return (y2-y1)/(x2-x1)
|
||||
|
||||
def eucDist(p1:float,p2:float) -> float:
|
||||
x1,y1 = p1
|
||||
x2,y2 = p2
|
||||
return ((x2 - x1)**2 + (y2 - y1)**2)**(1/2)
|
||||
|
||||
def y(x:float):
|
||||
return ((x**2) + (6*x) + 9)
|
||||
|
||||
def findLength(string1: str, string2:str) -> bool:
|
||||
return (len(string1) == len(string2))
|
||||
|
||||
def onIsInSentence(string1: str, string2:str) -> bool:
|
||||
return ("on" in string1 and "on" in string2)
|
||||
|
||||
def isInSentence(string1:str, string2:str) -> bool:
|
||||
return (string1 in string2)
|
||||
|
||||
def convertLenght(string: str) -> str:
|
||||
return (str)(float)(len(string))
|
||||
|
||||
def divAndRem(number:int) -> bool:
|
||||
return (number % 2 == 0)
|
||||
|
||||
def floorDiv(num1:int,num2:int) -> bool:
|
||||
return (num1 // num2 == int(2.7))
|
||||
|
||||
def typeCheck(element1, element2) -> bool:
|
||||
return (type(element1) == type(element2))
|
||||
|
||||
def checkIntnFloat(element1:str, element2:int) -> bool:
|
||||
return (int(float(element1)) == element2)
|
||||
|
||||
def payment(hours: int, rate: float) -> float:
|
||||
return hours*rate*7
|
||||
|
||||
def secondsLived(years: int):
|
||||
return years*365.25*24*60*60
|
||||
|
||||
def table(num: int):
|
||||
new_list = [num,1]
|
||||
for i in range(3):
|
||||
new_list.append(new_list[-1]*new_list[0])
|
||||
return new_list
|
||||
|
||||
|
||||
|
||||
|
||||
# 8, 9, 10 SLOPE
|
||||
|
||||
m1,x_int,y_int = slopeOne(2,-2)
|
||||
|
||||
m2= slopeBtwePnt((2,2),(6,10))
|
||||
dist = eucDist((2,2),(6,10))
|
||||
|
||||
print(f"Slope1: {m1}\nx-intercept: {x_int}\ny-intercept: {y_int}")
|
||||
|
||||
print(f"Slope2: {m2}\nDistance: {dist}")
|
||||
|
||||
print(f"Are slops ecual? {m1==m2}\n")
|
||||
|
||||
# 11 VALUE OF Y
|
||||
|
||||
# 18 Floor Division
|
||||
floor_num1 = 7
|
||||
floor_num2 = 3
|
||||
print(f"Floor division for {floor_num1} and {floor_num2} is ecual to integer for '2.7'", floorDiv(floor_num1,floor_num2))
|
||||
print()
|
||||
|
||||
|
||||
# 17 Evenness
|
||||
test_even_number = 4
|
||||
print(f"is {test_even_number} even?", divAndRem(4))
|
||||
print()
|
||||
|
||||
|
||||
# 19 Type equal
|
||||
tyec_val1 = '10'
|
||||
tyec_val2 = 10
|
||||
print(f"Are {tyec_val1} and {tyec_val2} types equal? {typeCheck(tyec_val1,tyec_val2)}")
|
||||
print()
|
||||
|
||||
|
||||
# 20 integer equal
|
||||
intec_val1 = '9.8'
|
||||
intec_val2 = 10
|
||||
print(f"is {intec_val1} equal to {intec_val2}?", checkIntnFloat(intec_val1,intec_val2))
|
||||
print()
|
||||
|
||||
|
||||
# 23 Lists
|
||||
print(table(1))
|
||||
print(table(2))
|
||||
print(table(3))
|
||||
print(table(4))
|
||||
print(table(5))
|
||||
print()
|
||||
|
||||
|
||||
# 21 Weekly payments
|
||||
hours = int(input("Enter hours: "))
|
||||
rate = float(input("Enter rate per hour: "))
|
||||
print(f"Your weekly earning is: {payment(hours, rate)}")
|
||||
print()
|
||||
|
||||
|
||||
# 22 Years lived
|
||||
years_lived = int(input("Enter number of years you lived: "))
|
||||
print(f"You have lived for {secondsLived(years_lived)} seconds aproximately")
|
||||
print()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user