Complete Python for Data Science AI & Development Quiz Answers [2025 Edition]

Get All Modules Python for Data Science AI & Development Quiz Answers

Module 01: Practice Quiz: Types

Q1. What is the data type of the entity 43?

Answer: int

Explanation: The number 43 is an integer, so its data type is int.


Q2. What data type does 3.12323 represent?

Answer: float

Explanation: The number 3.12323 is a decimal number, so its data type is float.


Q3. What is the result of the following: int(3.99)?

Answer: 3

Explanation: When converting a floating-point number like 3.99 to an integer using int(), the result is the integer part of the number, which is 3 (it truncates the decimal part).

Module 01: Practice Quiz: Expressions and Variables

Q1. What is the result of the operation: 11//2?

Answer: 5

Explanation: The // operator is floor division in Python, which divides and returns the largest integer less than or equal to the result. So, 11 divided by 2 is 5.5, but floor division rounds down to 5.


Q2. What is the value of x after the following is run:

pythonCopy codex = 4
x = x / 2

Answer: 2.0

Explanation: The operation x / 2 results in a floating-point number, so x becomes 2.0.


Q3. Which line of code will perform the action as required for implementing the following equation?

Equation: y = 2x² – 3

Answer: y = 2*x*x - 3

Explanation: The equation y = 2x² - 3 can be written as y = 2*x*x - 3 in Python, where x*x represents .

Module 01: Practice Quiz: String Operations

Q1. What is the result of the following? Name[-1]

Answer: “n”

Explanation: In Python, negative indexing accesses elements from the end of the string. So, Name[-1] refers to the last character in the string, which is “n” in “Michael Jackson”.


Q2. What is the result of the following? print("AB\nC\nDE")

Answer:

AB
C
DE

Explanation: The \n is a newline character, so it will print the text on separate lines.


Q3. What is the output of the following? "helloMike".find("Mike")

Answer: 5

Explanation: The find() method returns the index of the first occurrence of the specified substring. In “helloMike”, “Mike” starts at index 5.

Module 01 Graded Quiz: Python Basics

Q1. After executing the following lines of code, what value does x hold?

pythonCopy codex = 1  
x = x + 1  

Answer: 2

Explanation: Initially, x is set to 1. After the operation x = x + 1, x becomes 2.


Q2. What is the output of the following operation: 1 + 3 * 2?

Answer: 7

Explanation: In Python, multiplication is done before addition (order of operations). So 3 * 2 = 6, then 1 + 6 = 7.


Q3. What data type does the value "7.1" represent?

Answer: String

Explanation: The value "7.1" is enclosed in quotes, which makes it a string, not a float.


Q4. What is the output of the following code segment? int(False)

Answer: 0

Explanation: In Python, False is equivalent to 0 when converted to an integer.


Q5. In Python, what is the output of the following operation? '1' + '2'

Answer: ’12’

Explanation: Since both '1' and '2' are strings, they will be concatenated to form '12'.


Q6. Given myvar = 'hello', how would you return myvar as uppercase?

Answer: myvar.upper()

Explanation: The upper() method converts a string to uppercase.


Q7. What is the output of the following? str(1 + 1)

Answer: ‘2’

Explanation: The expression 1 + 1 equals 2, and str(2) converts the result into the string '2'.


Q8. What is the output of the following? "123".replace("12", "ab")

Answer: ‘ab3’

Explanation: The replace() method replaces the substring "12" with "ab", resulting in 'ab3'.


Q9. In Python 3, what data type does variable x hold after the operation: x = 1 / 1?

Answer: float

Explanation: In Python 3, division always results in a float, even if the result is an integer (e.g., 1 / 1 results in 1.0).


Q10. For the string "Fun Python" stored in a variable x, what will be the output of x[0:5]?

Answer: ‘Fun P’

Explanation: The slice x[0:5] extracts characters starting from index 0 up to (but not including) index 5, which gives 'Fun P'.

Module 02: Practice Quiz: Lists and Tuples

Q1. Consider the following tuple:

pythonCopy codesay_what = ('say', 'what', 'you', 'will')

What is the result of the following? say_what[-1]

Answer: ‘will’

Explanation: In Python, negative indexing starts from the end of the tuple. So, say_what[-1] refers to the last element, which is 'will'.


Q2. Consider the following tuple A:

pythonCopy codeA = (1, 2, 3, 4, 5)

What is the outcome of the following? A[1:4]

Answer: (2, 3, 4)

Explanation: Slicing with A[1:4] extracts elements from index 1 to 3, excluding index 4, so it results in (2, 3, 4).


Q3. Consider the following list B:

pythonCopy codeB = [1, 2, [3, 'a'], [4, 'b']]

What is the result of B[3][1]?

Answer: ‘b’

Explanation: B[3] refers to the list [4, 'b']. B[3][1] accesses the second element of this list, which is 'b'.


Q4. What is the outcome of the following operation?

pythonCopy code[1, 2, 3] + [1, 1, 1]

Answer: [1, 2, 3, 1, 1, 1]

Explanation: The + operator in lists performs concatenation, so the result is a combination of the two lists: [1, 2, 3] + [1, 1, 1] gives [1, 2, 3, 1, 1, 1].


Q5. After operating A.append([2, 3, 4, 5]), what will be the length of the list A = [1]?

Answer: 2

Explanation: The append() method adds an element to the end of the list. After A.append([2, 3, 4, 5]), the list A becomes [1, [2, 3, 4, 5]], so its length is 2.

Module 02: Practice Quiz: Dictionaries

Q1. What are the keys of the following dictionary?

pythonCopy code{"a":1, "b":2}

Answer: "a", "b"

Explanation: The keys of a dictionary are the items before the colon. In this case, "a" and "b" are the keys.


Q2. Consider the following Python Dictionary:

pythonCopy codeDict = {"A": 1, "B": "2", "C": [3, 3, 3], "D": (4, 4, 4), 'E': 5, 'F': 6}

What will be the outcome of the following operation? Dict["D"]

Answer: (4, 4, 4)

Explanation: The value of key "D" in the dictionary is the tuple (4, 4, 4).


Q3. Which of the following is the correct syntax to extract the keys of a dictionary as a list?

Answer: list(dict.keys())

Explanation: The keys() method returns the keys of a dictionary as a view object, which can be converted to a list using list().

Module 02: Practice Quiz: Sets

Q1. Consider the following set: {"A","A"}, what will the result be when you create the set?

Answer: {"A"}

Explanation: Sets in Python only contain unique elements. Duplicate elements are automatically removed, so {"A", "A"} results in {"A"}.


Q2. What method do you use to add an element to a set?

Answer: Add

Explanation: To add an element to a set in Python, you use the add() method.


Q3. What is the result of the following operation?

pythonCopy code{'a', 'b'} & {'a'}

Answer: {'a'}

Explanation: The & operator performs an intersection between two sets, meaning it returns only the common elements. In this case, the common element between {'a', 'b'} and {'a'} is 'a'.

Module 02 Graded Quiz: Python Data Structures

Q1. Examine the tuple A=((11,12),[21,22]), what is the outcome of the operation A[1]?

Answer: [21,22]

Explanation: The second element of the tuple A (index 1) is the list [21,22].


Q2. Consider the tuple A=((1),[2,3],[4]), what is the result of A[2]?

Answer: [4]

Explanation: The third element of the tuple A (index 2) is the list [4].


Q3. If L = ['c', 'd'], what is the output of L.append(['a', 'b'])?

Answer: ['c', 'd', ['a', 'b']]

Explanation: The append() method adds the entire list ['a', 'b'] as a single element to the list L.


Q4. What will list A=["hard rock", 10, 1.2] contain after the command del(A[0])?

Answer: [10, 1.2]

Explanation: The del statement removes the first element ("hard rock") from the list.


Q5. Which syntax clones list A and assigns the result to list B?

Answer: B = A[:]

Explanation: A[:] creates a shallow copy of the list A.


Q6. What is the result of len(("disco", 10))?

Answer: 2

Explanation: The tuple ("disco", 10) contains two elements, so its length is 2.


Q7. Consider the dictionary {"The Bodyguard":"1992", "Saturday Night Fever":"1977"}. Select the keys.

Answer: "The Bodyguard" and "Saturday Night Fever"

Explanation: The keys of the dictionary are the left-hand values in each key-value pair.


Q8. What is the outcome of release_year_dict.keys()?

Answer: Retrieves the keys of the dictionary

Explanation: The keys() method returns all the keys in the dictionary.


Q9. What is the result of V.add('C') for the set V={'A','B'}?

Answer: {'A','B','C'}

Explanation: The add() method adds the element 'C' to the set.


Q10. What is the outcome of '1' in {'1','2'}?

Answer: True

Explanation: The in operator checks if '1' is an element in the set {'1', '2'}. It is, so the result is True.

Module 03 Graded Quiz: Python Programming Fundamentals

Q1. What is the output of the following code?

x = "Gone" 
if x == "Go": 
    print('Go') 
else: 
    print('Stop') 
print('Mike')

Answer: The code evaluates the variable x to determine which block of code to execute. Here’s the breakdown:

x = "Gone" 
if x == "Go": 
    print('Go') 
else: 
    print('Stop') 
print('Mike')

Answer: Stop Mike

Q2. What is the result of the following lines of code?

x = 1 
x = x > -5

Answer: True

Q3. What is the result of the following few lines of code?

x = 0 
while x < 2: 
    print(x) 
    x = x + 1

Answer: 0,1

Q4. What is the result of running the following lines of code?

class Points(object): 
    def __init__(self, x, y): 
        self.x = x 
        self.y = y 
    def print_point(self): 
        print('x=', self.x, ' y=', self.y) 


p1 = Points(1, 2) 
p1.print_point()

Answer: x= 1 y= 2

Q5. What is the output of the following few lines of code?

for i, x in enumerate(['A', 'B', 'C']): 
    print(i + 1, x)

Answer: 1AA. 2BB, 3CC

Q6. What is the result of running the following lines of code?

class Points(object): 
    def __init__(self, x, y): 
        self.x = x 
        self.y = y 
    def print_point(self): 
        print('x=', self.x, ' y=', self.y) 


p2 = Points(1, 2) 
p2.x = 'A' 
p2.print_point()

Answer: x= A y= 2

Q7. Considering the function delta, when will the following function return a value of 1?

def delta(x): 
    if x == 0: 
        y = 1 
    else: 
        y = 0 
    return y

Answer: when the input is 0

Q8. What is the output of the following lines of code

a = 1 


def do(x): 
    return x + a 


print(do(1))

Answer: 2

Q9. Which three of the following functions will perform the addition of two numbers without any error?

Answer:

  1. def add(a, b): return(a+b)
  2. def add(a, b): c = a+b; return(c)
  3. def add(a, b): return(sum((a, b)))

Explanation:

  • return(a+b) correctly sums a and b.
  • c = a+b; return(c) also correctly sums a and b, storing the result in c.
  • return(sum((a, b))) works because sum() can take a tuple or list of numbers as input.
  • The function return(sum(a, b)) would raise an error because sum() only takes one argument as a sequence.

Q10. Why is it best practice to have multiple except statements with each type of error labeled correctly?

Answer: To determine the type of error thrown and its location within the program

Explanation: Using multiple except statements allows specific handling of different error types, which aids in debugging and ensures appropriate corrective actions. This approach provides better insights into the program’s behavior and prevents generic handling of all errors.

Module 04 Graded Quiz: Working with Data in Python

Q1. What result will the following lines of code give?

pythonCopy codea = np.array([0, 1])
b = np.array([1, 0])
np.dot(a, b)

Answer: 0

Explanation: The dot product of vectors a and b is calculated as (0×1)+(1×0)=0(0 \times 1) + (1 \times 0) = 0(0×1)+(1×0)=0.


Q2. How do you perform matrix multiplication on the Numpy arrays A and B?

Answer: np.dot(A, B)

Explanation: The np.dot() function in Numpy is used to perform matrix multiplication.


Q3. If you run the following lines of code, what values will the variable ‘out’ take?

pythonCopy codeX = np.array([[1, 0, 1], [2, 2, 2]])
out = X[0:2, 2]

Answer: array([1, 2])

Explanation: The slicing X[0:2, 2] selects the 3rd column from the first and second rows, resulting in [1, 2].


Q4. After executing the given code, what value does Z hold?

pythonCopy codeX = np.array([[1, 0], [0, 1]])
Y = np.array([[2, 1], [1, 2]])
Z = np.dot(X, Y)

Answer: array([[2, 1], [1, 2]])

Explanation: Matrix multiplication of XXX (identity matrix) with YYY leaves YYY unchanged.


Q5. What is the output of the following lines of code?

pythonCopy codewith open("Example1.txt", "r") as file1:
    file_stuff = file1.readline()
print(file_stuff)

Answer: This is line 1

Explanation: The readline() method reads only the first line from the file.


Q6. What mode is the file object in?

pythonCopy codewith open(example1, "r") as file1:

Answer: read

Explanation: The mode "r" opens the file in read-only mode.


Q7. What do the following lines of code do?

pythonCopy codewith open("Example.txt", "w") as writefile:
    writefile.write("This is line A\n")
    writefile.write("This is line B\n")

Answer: Write to the file "Example.txt"

Explanation: The "w" mode writes data to the file. If the file exists, its content will be overwritten.


Q8. What do the following lines of code do?

pythonCopy codewith open("Example3.txt", "w") as file1:
    file1.write("This is line C\n")

Answer: Write to the file “Example3.txt”

Explanation: The "w" mode opens the file for writing, creating it if it doesn’t exist.


Q9. Given the dataframe df, how can you retrieve the element in the second row and first column?

Answer: df.iloc[1, 0]

Explanation: The iloc method uses zero-based indexing, so the second row is index 1, and the first column is index 0.


Q10. What function would you use to load a CSV file in Pandas?

Answer: pd.read_csv(path)

Explanation: pd.read_csv() is the function to load a CSV file into a Pandas DataFrame.

Module 05 Graded Quiz: APIs and Data Collection

Q1. What are the three parts of a response message?

Answer: Start or status line, header, and body

Explanation: In an HTTP response, the status line contains the status code and reason phrase, the header contains metadata, and the body contains the content or data.


Q2. What does the line of code table_row = table.find_all(name='tr') do in web scraping?

Answer: It locates all the data within the table marked with a tag “tr”

Explanation: The find_all method searches for all occurrences of a specified tag. Here, it retrieves all <tr> (table row) elements.


Q3. What data structure do HTTP responses typically use for their return?

Answer: JSON

Explanation: Most HTTP responses, especially in APIs, use JSON to structure the data, as it’s lightweight and easy to parse.


Q4. Complete the sentence. The Python library we used to plot the graphs is ______.

Answer: matplotlib

Explanation: Matplotlib is a widely used library for creating static, interactive, and animated visualizations in Python.


Q5. What is the role of the ‘td’ tag in HTML files?

Answer: Table cell data

Explanation: The <td> tag defines a cell within a table row, holding individual data items within a table.

All Lab Assessment of Python for Data Science AI & Development

Lab Assessment – Sets

Click here to Download

Conditions and Branching Quiz Answers

Click here to Download Quiz Answers

Lab Assement

Click Here to Download

Loop – Quiz Answers

Click Here to Download

Lab Assement

Click Here to Download

Function – Quiz Answers

Click Here to Download

Lab Assement

Click Here to Download

Classes – Quiz Answers

Click Here to Download

Lab Assement

Click Here to Download

Reading Files with Open – Quiz Answers

Click here to Download Quiz Answers

Lab Assement

Click Here to Download

Writing with File Open – Quiz Answers

Click here to Download Quiz Answers

Lab Assement

Click Here to Download

Pandas – Quiz Answers

Click here to Download Quiz Answers

Lab Assement

Click Here to Download

One Dimensonal Numpy – Quiz Answers

Click here to Download Quiz Answers

Lab Assement

Click Here to Download

Two Dimensonal Numpy – Quiz Answers

Click here to Download Quiz Answers

Lab Assement

Click Here to Download

Simple API – Quiz Answers and Lab

LAB 1: Intro API: Click Here to Download or Link 2

LAB 2: API 2: Click Here to Download or Link 2

Lab String Assessment

Click here to Download

Quiz String Operations Docx

Click here to Download

Lab 1: Tupels

Click here to Download

Lab 2: Strings

Click here to Download

Lab Assements – Dictionary

Click here to Download

Click here to Download Quizzes and Lab Assement

Final Assessment – Python Dashboard

Next Quiz Answers >>

Course 5: Python Project for Data Science

<< Previous Quiz Answers

Course 3: Data Science Methodology

All Quiz Answers of multiple Specializations or Professional Certificates programs:

Course 1: What is Data Science?

Course 2: Tools for Data Science

Course 3: Data Science Methodology

Course 4: Python for Data Science, AI & Development

Course 5: Python Project for Data Science

Course 6: Databases and SQL for Data Science with Python

Course 7: Data Analysis with Python

Share your love

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *