Finished day 3

This commit is contained in:
2026-01-22 16:18:49 -06:00
parent aea0c85397
commit c6323a9974

View File

@@ -1,5 +1,9 @@
# 1
age:int = 20 age:int = 20
# 2
height: float = 1.76 height: float = 1.76
# 3
complexNum: complex = 1 + 3j complexNum: complex = 1 + 3j
def areaOfTriangle(base:float, height: float) -> float: def areaOfTriangle(base:float, height: float) -> float:
@@ -9,11 +13,11 @@ def sideOfTriangle(a: int, b: int, c: int) -> int:
return (a+b+c) return (a+b+c)
def dataOfRectangle(length: float, width: float) -> [float, float]: def dataOfRectangle(length: float, width: float) -> [float, float]:
return [length*width, (2*(lenght+width))] return [length*width, (2*(length+width))]
def dataOfCircle(radius:float) -> [float, float]: def dataOfCircle(radius:float) -> [float, float]:
pi = 3.14 pi = 3.14
return [pi * (r**2), (2*pi)*(radius*2)] return [pi * (radius**2), pi*(radius*2)]
def slopeOne(a:float, b:float) -> (float,float,float): def slopeOne(a:float, b:float) -> (float,float,float):
slope = a slope = a
@@ -31,8 +35,8 @@ def eucDist(p1:float,p2:float) -> float:
x2,y2 = p2 x2,y2 = p2
return ((x2 - x1)**2 + (y2 - y1)**2)**(1/2) return ((x2 - x1)**2 + (y2 - y1)**2)**(1/2)
def y(x:float): def f(x:float):
return ((x**2) + (6*x) + 9) return ((x*x) + (6*x) + 9)
def findLength(string1: str, string2:str) -> bool: def findLength(string1: str, string2:str) -> bool:
return (len(string1) == len(string2)) return (len(string1) == len(string2))
@@ -44,7 +48,7 @@ def isInSentence(string1:str, string2:str) -> bool:
return (string1 in string2) return (string1 in string2)
def convertLenght(string: str) -> str: def convertLenght(string: str) -> str:
return (str)(float)(len(string)) return (str)((float)(len(string)))
def divAndRem(number:int) -> bool: def divAndRem(number:int) -> bool:
return (number % 2 == 0) return (number % 2 == 0)
@@ -70,8 +74,27 @@ def table(num: int):
new_list.append(new_list[-1]*new_list[0]) new_list.append(new_list[-1]*new_list[0])
return new_list return new_list
# 4
tri_base = int(input("Enter base: "))
tri_heig = int(input("enter height: "))
print("The area of triangle is:", areaOfTriangle(tri_base, tri_heig))
# 5
tri_a = int(input("Enter side a: "))
tri_b = int(input("Enter side b: "))
tri_c = int(input("Enter side c: "))
print("The perimeter of triangle is:", sideOfTriangle(tri_a,tri_b,tri_c))
# 6
rec_w = int(input("\nEnter width of rectangle: "))
rec_h = int(input("Enter height of rectangle: "))
recData = dataOfRectangle(rec_w,rec_h)
print(f"Area of rectangle is {recData[0]}\nPerimeter of rectangle is {recData[1]}.\n")
# 7
cir_radius = int(input("Enter radius of a circle: "))
dataCir = dataOfCircle(cir_radius)
print(f"Area of circle: {dataCir[0]}\nCircumference of circle is: {dataCir[1]}\n")
# 8, 9, 10 SLOPE # 8, 9, 10 SLOPE
@@ -87,6 +110,30 @@ print(f"Slope2: {m2}\nDistance: {dist}")
print(f"Are slops ecual? {m1==m2}\n") print(f"Are slops ecual? {m1==m2}\n")
# 11 VALUE OF Y # 11 VALUE OF Y
print(f"y = {f(2)}")
print(f"{f(-3)} = 0\n")
# 12 LENGTH AND COMPARISON
l_str1 = "python"
l_str2 = "dragon"
print(f"are {l_str1} and {l_str2} equal?", findLength(l_str1, l_str2))
# 13 AND
print(f"is 'on' in {l_str1} and in {l_str2}?", onIsInSentence(l_str1,l_str2))
print()
# 14 substrings
string = "I hope this course is not full of jargon"
substring = "jargon"
print(f"is {substring} in {string}", isInSentence(substring, string))
print()
# 15 NOT
print(f"is 'on' not in {l_str1} and in {l_str2}?", not onIsInSentence(l_str1,l_str2))
# 16 Convert length to float and then to string
convertedLength = convertLenght(l_str1)
print(f"Length in {l_str1} is\n{type(convertedLength)} -> {convertedLength}")
# 18 Floor Division # 18 Floor Division
floor_num1 = 7 floor_num1 = 7