lab1python
lab1python
"""Demo1.ipynb
import random
luckyStudent = random.randint(1,65)
print(f"Lucky Student - (luckyStudent)")
a=4
b=5
a,b = b,a
print(a,b)
dm = cm / 10
inch = cm * 0.393701
import random
import random
if number > 0:
print("Đây là số dương.")
elif number < 0:
print("Đây là số âm")
else:
print("Đây là số 0.")
import random
import math
hour = hour % 12
angle_in_radian = math.radians(angle_in_degree)
import math
a = 1
b = 5
c = 6
if discriminant > 0:
print("Step 3: Discriminant > 0, so the equation has two distinct real roots.")
root = -b / (2 * a)
print(f"Step 4: Root is calculated as:")
print(f"x = -b / 2a = {-b} / (2*{a}) = {root:.2f}")
else:
print("Step 3: Discriminant < 0, so the equation has two complex roots.")
real_part = -b / (2 * a)
imaginary_part = math.sqrt(abs(discriminant)) / (2 * a)
print(f"Step 4: Roots are calculated as:")
print(f"x1 = {-b} / (2*{a}) + i√{abs(discriminant)} / (2*{a}) = {real_part:.2f}
+ {imaginary_part:.2f}i")
print(f"x2 = {-b} / (2*{a}) - i√{abs(discriminant)} / (2*{a}) = {real_part:.2f}
- {imaginary_part:.2f}i")
words = text.split()
word_count = len(words)
print(f"Step 1: The total number of words in the string is: {word_count}")
has_number = False
for index, word in enumerate(words):
if word.isdigit():
has_number = True
print(f"Step 2: Found a number '{word}' at position {index + 1} (1-based
index)")
if not has_number:
print("Step 2: No numbers were found in the string.")
import math
dot_product = x1 * x2 + y1 * y2
magnitude_p1 = math.sqrt(x1**2 + y1**2)
magnitude_p2 = math.sqrt(x2**2 + y2**2)
if magnitude_p1 == 0 or magnitude_p2 == 0:
cosine_distance = 1.0
print("Cosine Distance: Undefined (division by zero). Assuming 1.")
else:
cosine_similarity = dot_product / (magnitude_p1 * magnitude_p2)
cosine_distance = 1 - cosine_similarity
print(f"Cosine Distance: {cosine_distance:.2f}")
from datetime import datetime
weekday_name = birthday.strftime("%A")
month_name = birthday.strftime("%B")
today = datetime.now()
age = today.year - birthday.year
if (today.month, today.day) < (birthday.month, birthday.day):
age -= 1
import pandas as pd
data = {
'Customer': customers,
'Product': products,
'QuantityList': quantity_list
}
df = pd.DataFrame(data)
df['Quantity'] = pd.to_numeric(df['Quantity'])