Absolute Imports In Packages
Mon 10 August 2026
from my_package.analytics.stats import calculate_mean
Score: 5
Category: chapter10_modules_and_packages
from my_package.analytics.stats import calculate_mean
Score: 5
Category: chapter10_modules_and_packages
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self):
pass
class Rectangle(Shape):
def area(self):
return 10 * 5
shape = Rectangle()
print(shape.area())
50
Score: 10
Category: chapter4_polymorphism
Read Moreimport csv
with open("data.csv", "r") as file:
reader = csv.DictReader(file)
for row in reader:
print(row["name"], row["age"])
Alice 25
Bob 30
Score: 10
Category: chapter11_csv_handling
Read MoreAdd a New Column
import pandas as pd
data = {
'city' : ['Toronto', 'Montreal', 'Waterloo'],
'points' : [80, 70, 90]
}
data
{'city': ['Toronto', 'Montreal', 'Waterloo'], 'points': [80, 70, 90]}
type(data)
dict
df = pd.DataFrame(data)
df
Category: pandas-work
Read Moreclass Animal:
def sound(self):
print("Some sound")
class Dog(Animal):
def bark(self):
print("Dog barks")
d = Dog()
d.sound()
d.bark()
Some sound
Dog barks
Score: 10
Category: chapter2_inheritance
Read Morea=10
b=80
c=a+b
c
90
Score: 15
Category: math-work
Read Morefrom datetime import datetime
def get_age(d):
d1 = datetime.now()
months = (d1.year - d.year) * 12 + d1.month - d.month
year = int(months / 12)
return year
age = get_age(datetime(1991, 1, 1))
age
33
Score: 25
Category: misc
Read Moreimport csv
with open("users.csv", "a", newline="") as file:
writer = csv.writer(file)
writer.writerow(["Charlie", 40, "USA"])
Score: 10
Category: chapter11_csv_handling
Read Moreimport csv
with open("users.csv", "a", newline="") as file:
writer = csv.writer(file)
writer.writerow(["Charlie", 40, "Canada"])
Score: 10
Category: chapter11_csv_handling
Read Moreconfig = {"theme": "dark"}
def update_config(new_theme):
config["theme"] = new_theme # No global keyword needed
Score: 10
Category: chapter13_global_and_scope
Read More