Solutions
Day 1 afternoon
# Example 1: Basic text output
print("Welcome to Digital Humanities")
# Example 2: Working with a string
sentence = "Humanities meet computation"
print("Length of sentence:", len(sentence))
# Example 3: Check data type
number = 42
print("Data type:", type(number))
# Example 4: Sorting a list
years = [1850, 2023, 1945, 1789]
print("Sorted years:", sorted(years))
# Example 5: Using range and sum
print("Sum from 1 to 5:", sum(range(1, 6))) # 1+2+3+4+5 = 15help(str)
?str
str?
help(len)import math
print(math.sqrt(16))
from math import pi, sin
print(pi)
print(sin(pi/2))
import numpy as np
array = np.array([1, 2, 3])
arrayimport random
print(random.randint(1, 10)) # Random number between 1 and 10
import datetime
now = datetime.datetime.now()
print(now.strftime("%Y-%m-%d %H:%M:%S"))
import os
print(os.getcwd()) # Current working directory
print(os.listdir()) # List files in the current directorypip install numpy
pip install pandas
pip install matplotlib
import numpy as np
arr = np.array([1, 2, 3])
print(arr * 2)
import pandas as pd
data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]}
df = pd.DataFrame(data)
print(df)
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
plt.plot(x, y)
plt.title("Simple Line Plot")
plt.show()