📝 Practice Assignments

Test your Python skills with 50 hands-on questions!

📘 Course source: extra assignments & practice

In the course source you also have Assignment 1–7 (notebooks: data types, data structures, functions, OOP, NumPy, Pandas, regression), Practice Questions on Maths, and Additional Python / Pandas Questions. Use them for extra practice; the same topics are covered here (a1–a5) and in the Data Science course.

📚

Student Practice

Practice questions to test your knowledge. Try solving them yourself first!

  • All 50 practice questions
  • Difficulty indicators
  • Topic-wise organization
  • Hints for each question
Start Practice →
🔐

Instructor Access

View complete solutions with detailed explanations. Requires passcode.

  • 🔒 Complete solutions
  • 🔒 Step-by-step explanations
  • 🔒 Alternative approaches
  • 🔒 Teaching notes

📋 Assignment Overview

Complete code from course notebook: Assignment_1.ipynb

Every line of code from the course notebook (verbatim).


      

Complete code from course notebook: Assignment_2.ipynb

Every line of code from the course notebook (verbatim).

# --- Code cell 2 ---
 ### Please name your assignment file using the following format: Your Name_Assignment_Assignment Number. EX: INTTRVU_Assignment_1

Complete code from course notebook: Assignment_3.ipynb

Every line of code from the course notebook (verbatim).


      

Complete code from course notebook: Assignment_4.ipynb

Every line of code from the course notebook (verbatim).


      

Complete code from course notebook: Assignment_5.ipynb

Every line of code from the course notebook (verbatim).

# --- Code cell 4 ---
### Q1) Write a python Class Circle which has the following variables and functions.

#Variables:
#pi_value = 3.14 (private variable)
#radius 

#functions:
#area_calculator
#circumference_calculator


#Create an object of Class circle and calculate its area and circumference.

# --- Code cell 6 ---
#Q2) Write a function which returns the addition of all numbers in numpy array.
# Numpy array should contain 50 random numbers in the range of 10 to 100 generated using random number generator.

# --- Code cell 8 ---
# Q3) i) Create a 3 * 2 ( 3 rows , 2 columns ) matrix using numpy and transpose it.
#ii) After transposing print the first row of matrix ( index 0)
#iii) Print second element in first row
#iv) Flatten the matrix to 1D ( 1 Dimensional ) array
#v) Print maximum, minimum and average value of 1D array

# --- Code cell 11 ---
#Q4) 	Read the Housing.csv file in your notebook and perform the following operations.
#i)	Calculate average and median price per square foot area (assume area column’s unit is sq ft )
#ii)	Calculate median price per bedroom. 
#iii)	Calculate average price per sq ft for furnished, semi-furnished and unfurnished homes.
#iv)	Are homes with guestrooms AND main road location costlier than remaining houses? Analyze the data using pandas to come up with your answer.
#v)	 Convert the values in air conditioning columns to 0 and 1 using lambda function
#vi)	Create a new column with the name price_index. Assign it 1 if the price of house is higher than average price else assign it value 0
#vii)	Sort the data by area, bathrooms and bedrooms column in descending order

Complete code from course notebook: assignment_6.ipynb

Every line of code from the course notebook (verbatim).

# --- Code cell 3 ---
# Question 1
# What is the difference between continuous and discrete random variable?

# --- Code cell 5 ---
# Question 2
# What is inter quartile range?

# --- Code cell 7 ---
# Question 3
# How we can impute missing values for numerical and categorical features.

# --- Code cell 9 ---
# Question 4
# What is the significance of p-value

# --- Code cell 11 ---
# Questions 5
# If your numerical data has outliers how you would progress with missing value imputation?

# --- Code cell 13 ---
# Question 6
# What is contingency table in chi-square test?

# --- Code cell 15 ---
# Question 7
# Company wants to understand whether older version of newer version of product is better for the market based on customer reviews
# How would you prove that older/newer version is better statistically?

# --- Code cell 17 ---
# Question 8
# What is the difference between sample and population?

# --- Code cell 19 ---
# Question 9
# How would you decide product placement in DMart store if you have purchase data of 10,000 transactions
# Which factors are important to increase the sales based on product placement?

# --- Code cell 21 ---
# Question 10
# Explain the difference between correlation and causation with example.

# --- Code cell 23 ---
#Question 11
# Use Hotel reservations data from the sessions and solve following
# Does 'market_segment_type' have any impact on booking cancellation?
# Does 'no_of_special_requests' have any impact on booking cancellation?

# clue: use hypothesis testing

# --- Code cell 26 ---
#Question 12
# Use Hotel reservations data from the sessions and solve following
# Is there any correlation between 'lead_time' and 'avg_price_per_room'?
# If 'arrival_date' is after 25th of any month is there higher or lower cancellation rate a compareto first 25 days of the month?

# --- Code cell 28 ---
#Question 13
# Use Hotel reservations data from the sessions and solve following
# Draw histogram with 20 bins for 'lead_time' and 'avg_price_per_room'?
# Use matplotlib and draw it
# then use seaborn and draw it

# --- Code cell 30 ---
# Question 14
# Write following equations/mathematical formulas in your notebook - 5 times each
# No need to submit answer of this question in your submission
# Just write DONE over here if you have completed this step

# variance
# standard deviation
# Euclidean distance
# cosine distance
# min max scalar
# Normal distribution

Complete code from course notebook: assignment_7.ipynb

Every line of code from the course notebook (verbatim).

# --- Code cell 3 ---
# Question 1
# What are the assumptions of linear regression?

# --- Code cell 6 ---
# Question 2
# What is MAE and R Squared score? In which case you will prefer R Squared Score?

# --- Code cell 9 ---
# Question 3
# What is the impact of very high learning rate in gradient descent?

# --- Code cell 12 ---
# Question 4
# Which property of logistic function is useful for a classification model?

# --- Code cell 15 ---
# Question 5
# Is feature scaling recommended for linear regression and logistic regression? If yes, why?

# --- Code cell 18 ---
# Question 6
# What is odds ratio?

# --- Code cell 21 ---
# Questions 7
# What is a cost function? Write in simple words.

# --- Code cell 24 ---
# Question 8
# What is precision and recall?

# --- Code cell 27 ---
# Question 9
# What is decision boundary?

# --- Code cell 30 ---
# Question 10
# Can logistic regression handle non-linear decision boundary?

# --- Code cell 33 ---
# Question 11
# What is bias variance tradeoff?

# --- Code cell 36 ---
# Question 12
# What will likely happen if we increase the number of features. Overffiting or underfitting?

# --- Code cell 39 ---
# Question 13
# Which type of regularization is preferred for feature selection?

# --- Code cell 42 ---
# Question 14
# Build and evaluate a linear regression model for predicting insurance charges.
# Refer insurance.csv dataset which is kept in the same folder

# --- Code cell 46 ---
# Question 15
# Write following formulas in your notebook 5 times each
# You dont have submit the solution for this question

# Linear regression equation
# Linear regression cost function
# gradient descent formula
# Logistic regression equation
# Logistic regression cost function
# MAE, RMSE, R Squared Score
# Precision and Recall
# L1 regularization
# L2 regularization

Complete code from course notebook: Practice Questions on Maths.ipynb

Every line of code from the course notebook (verbatim).

# --- Code cell 4 ---
import pandas as pd

data = {
    'Student': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'],
    'Math': [88, 72, 91, 65, 85, 77, 94, 81, 70, 83],
    'English': [75, 80, 82, 69, 86, 73, 89, 78, 74, 80],
    'Science': [90, 78, 85, 70, 88, 76, 92, 84, 77, 86],
    'Study Hours': [6, 5, 7, 3, 6, 4, 8, 5, 4, 6],
    'Attendance': [95, 82, 98, 76, 90, 80, 99, 88, 78, 92],
    'Extracurricular': ['Yes', 'No', 'Yes', 'Yes', 'No', 'No', 'Yes', 'No', 'Yes', 'Yes']
}

df = pd.DataFrame(data)
df

Complete code from course notebook: Pandas_Questions.ipynb

Every line of code from the course notebook (verbatim).


      

Complete code from course notebook: Python_Coding_Qs.ipynb

Every line of code from the course notebook (verbatim).

# --- Code cell 30 ---
Ex :
Input: 
name = "Alice"
age = 25

Output: Hello, Alice! You are 25 years old.

# --- Code cell 221 ---
Output : 
['Name', 'Age', 'Courses']
['John', 20, ['Math', 'Science']]

# --- Code cell 223 ---
# dict1 = {'a': 1, 'b': 2}
# dict2 = {'b': 3, 'c': 4}

# --- Code cell 224 ---
Output:{'a': 1, 'b': 3, 'c': 4}

# --- Code cell 226 ---
Output:{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

# --- Code cell 228 ---
# School
#     Class 1
#         Students: ['Alice', 'Bob']
#     Class 2
#         Students: ['Charlie', 'David']

# --- Code cell 281 ---
# tuple1 = (1, 2, 3)
# tuple2 = (4, 5, 6)

# --- Code cell 301 ---
# data = {
#     'Name': ['Alice', 'Bob', 'Charlie'],
#     'Age': [25, 30, 35],
#     'City': ['New York', 'Los Angeles', 'Chicago']
# }

# --- Code cell 318 ---
# data_with_nan = {
#     'Name': ['Alice', 'Bob', 'Charlie'],
#     'Age': [25, None, 35],
#     'City': ['New York', 'Los Angeles', 'Chicago']
# }

# --- Code cell 322 ---
# df1 = pd.DataFrame({'ID': [1, 2, 3], 'Name': ['Alice', 'Bob', 'Charlie']})
# df2 = pd.DataFrame({'ID': [1, 2, 4], 'Salary': [50000, 60000, 70000]})

# --- Code cell 324 ---
### City: 'New York', 'Los Angeles', 'Chicago', 'New York', 'Los Angeles'
### Month: 'Jan', 'Jan', 'Feb', 'Feb', 'Jan'
### Sales: 2000, 3000, 2500, 3500, 2800

# --- Code cell 336 ---
# data_dup = {
#     'Name': ['Alice', 'Bob', 'Alice', 'Charlie'],
#     'Age': [25, 30, 25, 35]
# }

# --- Code cell 364 ---
# array1 = np.array([1, 2, 3])
# array2 = np.array([4, 5, 6])

# --- Code cell 368 ---
# array1 = np.array([1, 2, 3])
# array2 = np.array([4, 5, 6])

# --- Code cell 372 ---
# array1 = np.array([1, 2, 3])
# array2 = np.array([4, 5, 6])

# --- Code cell 382 ---
# array = np.array([1, 2, 3, 4, 5])

# --- Code cell 386 ---
# array = np.array([1, 2, 3, 4, 5])

# --- Code cell 390 ---
# array = np.array([1, 2, 3, 4, 5])

# --- Code cell 393 ---
# matrix1 = np.array([[1, 2], [3, 4]])
# matrix2 = np.array([[5, 6], [7, 8]])

# --- Code cell 465 ---
Input : 5

Output : Positive

# --- Code cell 468 ---
Input : 4
Output : Even

# --- Code cell 471 ---
Input : 2023
Output : NO

# --- Code cell 483 ---
Input :  Race
Output : Not a Palindrome