Module 1 Test: Python Foundations
Questions cover Chapters 1-4 in Module 1.
This is your progress tracker . 20 questions: 5 Easy, 10 Moderate, 5 Hard . Solve all the questions on your own first (work out the output in your head before running the code in Colab), then check with the Answer Key.
| Score | Meaning |
|---|---|
| 18 to 20 | Excellent! Your grip on Module 1 is strong. |
| 12 to 17 | Good. Re-read the chapters for the questions you got wrong. |
| Below 12 | Do not worry. Re-read Chapters 2 and 3, run the code yourself, then take the test again. |
EASY
Q1. Which of the following is a valid Python variable name?
A) 2name
B) my-name
C) my_name
D) class
EASY
Q2. What is the result of type(3.14)?
A) int
B) str
C) bool
D) float
EASY
Q3. Which symbol starts a comment in Python?
A) //
B) #
C) /*
D) --
EASY
Q4. What is the index of the first element of a list?
A) 1
B) -1
C) 0
D) 2
EASY
Q5. Among AI, Machine Learning and Deep Learning, which is the biggest circle?
A) Artificial Intelligence
B) Machine Learning
C) Deep Learning
D) All three are equal
MODERATE
Q6. What will be the output of this code?
print(7 // 2)
A) 3.5
B) 3
C) 4
D) 1
MODERATE
Q7. In which type does the input() function return the user's typed answer?
A) int
B) float
C) str (string)
D) Whatever type the user types
MODERATE
Q8. What will be the output of this code?
nums = [10, 20, 30, 40, 50]
print(nums[1:4])
A) [10, 20, 30, 40]
B) [20, 30, 40]
C) [20, 30, 40, 50]
D) [10, 20, 30]
MODERATE
Q9. What will be the output of this code?
print(len({1, 2, 2, 3, 3, 3}))
A) 6
B) 3
C) 4
D) Error
MODERATE
Q10. What will be the output of this code?
d = {"a": 1}
print(d.get("b", 0))
A) None
B) A KeyError will occur
C) 0
D) 1
MODERATE
Q11. Which of the following data types is mutable (can be changed after it is created)?
A) tuple
B) string
C) int
D) list
MODERATE
Q12. What will be the output of this code?
total = 0
for i in range(1, 6):
if i == 3:
continue
total += i
print(total)
A) 15
B) 12
C) 10
D) 6
MODERATE
Q13. What will be the output of this code?
def f():
print("hi")
x = f()
print(x)
A) Only hi
B) Only None
C) First line hi, second line None
D) Error
MODERATE
Q14. Which is the correct order of the initial steps of the Data Science Pipeline?
A) Problem Definition, Data Collection, Data Cleaning, EDA
B) Data Cleaning, Problem Definition, EDA, Data Collection
C) EDA, Data Collection, Problem Definition, Data Cleaning
D) Data Collection, EDA, Problem Definition, Data Cleaning
MODERATE
Q15. What happens when a file is opened with open("a.txt", "w")?
A) The old content stays and the new content is added at the end
B) It can only be read
C) The old content is erased and the new content is written
D) An error occurs if the file does not exist
HARD
Q16. What will be the output of this code?
x = 5
def f():
x = 10
print(x)
f()
print(x)
A) 10 then 10
B) 5 then 5
C) 10 then 5
D) 5 then 10
HARD
Q17. What will be the output of this code?
a = [1, 2, 3]
b = a
b.append(4)
print(a)
A) [1, 2, 3]
B) [1, 2, 3, 4]
C) [4]
D) Error
HARD
Q18. What will be the output of this code?
s = "Data Science"
print(s[::-1][:4])
A) Data
B) ecne
C) ecnei
D) Scie
HARD
Q19. What will be the output of this code?
class A:
def hi(self):
print("A")
class B(A):
def hi(self):
super().hi()
print("B")
B().hi()
A) Only B
B) Only A
C) A then B
D) B then A
HARD
Q20. What will be the output of this code?
a = {1, 2, 3, 4}
b = {3, 4, 5}
print(sorted(a ^ b))
A) [3, 4]
B) [1, 2]
C) [1, 2, 5]
D) [1, 2, 3, 4, 5]
MODULE 1 TEST
Module 1 Answer Key (Answers and Explanations)
| # | Level | Answer | Explanation |
|---|---|---|---|
| 1 | Easy | C) my_name | A name cannot start with a number, '-' does not work in it, and 'class' is a Python keyword. my_name is correct. |
| 2 | Easy | D) float | A number with a decimal is called a float. |
| 3 | Easy | B) # | In Python a comment starts with #. Python ignores that line. |
| 4 | Easy | C) 0 | In Python the index always starts from 0. |
| 5 | Easy | A) Artificial Intelligence | AI is the biggest, ML is inside it, and DL is inside ML. |
| 6 | Moderate | B) 3 | // is floor division and gives only the whole part: 7 // 2 = 3. (For 3.5 you use /.) |
| 7 | Moderate | C) str (string) | input() always gives a string. If you want a number you have to apply int() or float(). |
| 8 | Moderate | B) [20, 30, 40] | The slice [1:4] starts at index 1 and stops before index 4 (4 is not included). |
| 9 | Moderate | B) 3 | A set removes duplicates by itself, so only 3 remains, whose length is 3. |
| 10 | Moderate | C) 0 | If the key is not found, get() does not give an error but returns the given default value (0). |
| 11 | Moderate | D) list | A list is mutable. Tuple, string and int are immutable. |
| 12 | Moderate | B) 12 | continue skips i == 3. So 1 + 2 + 4 + 5 = 12. |
| 13 | Moderate | C) First line hi, second line None | f() printed 'hi', but there was no return, so x became None and that was printed too. |
| 14 | Moderate | A) Problem Definition, Data Collection, Data Cleaning, EDA | First the problem is defined, then data is collected, then cleaned, and then EDA is done. |
| 15 | Moderate | C) The old content is erased and the new content is written | "w" mode erases the old content. To keep the old content use "a" (append). |
| 16 | Hard | C) 10 then 5 | x = 10 inside the function is a local variable. The outside global x stays 5. |
| 17 | Hard | B) [1, 2, 3, 4] | b = a does not make a copy; both are names of the same list. So a change in b is visible in a as well. |
| 18 | Hard | B) ecne | s[::-1] gives "ecneicS ataD", then [:4] gives the first four letters: "ecne". |
| 19 | Hard | C) A then B | B's hi() first prints the parent's A through super().hi(), then prints its own B. |
| 20 | Hard | C) [1, 2, 5] | ^ is the symmetric difference: the items that are not common to both. 3 and 4 drop out, so [1, 2, 5]. |
Your score: ______ / 20