Table of Contents
Get All Weeks Programming in Python Coursera Quiz Answers
Week 1: Programming in Python Coursera Quiz Answers
Quiz 1: Knowledge check – Welcome to Python Programming
Question 1: Is a string in Python a sequence?
- Yes
- No
Question 2: In Python, what symbol is used for comments in code?
- //
- —
- #
Question 3: What type will be assigned to the following variable: x = 4?
- str – String
- int – Integer
- float – Float
- list – List
Question 4: Python allows for both implicit and explicit data type conversions?
- True
- False
Question 5: A variable called name is assigned the value of “Testing”. What will the output of the following equal – print(len(name));
- Testing
- Error
- str
- 7
Quiz 2: Self-review: Use control flow and loops to solve a problem
Question 1: Python for loops works on any type of sequence data type including strings.
- True
- False
Question 2: The enumerate function is used to provide the index of the current iteration of a for a loop.
- True
- False
Question 3: A break statement can be used to exit out of a for loop based on a certain condition being satisfied.
- True
- False
Quiz 3: Module quiz: Getting Started with Python
Question 1: Python is a dynamically typed language. What does this mean?
- Python supports both functional and object-oriented programming.
- Python requires you to explicitly set the correct data type and value before assigning a variable.
- Python does not require a type for a variable declaration. It automatically assigns the data type at run time.
- Python requires that you specify the type of variable before it is assigned.
Question 2: How do you create a block in Python?
- A block is created using a colon followed by a new line and indentation
- A block is created by a new line
- A block is created using a semi-colon and a new line
- A block is created using a semi-colon and indentation
Question 3: When declaring a variable in Python, can a variable name contain white space?
- Yes
- No
Question 4: How can a variable be deleted in python?
- The del keyword
- The remove keyword
- The def keyword
- A variable cannot be deleted
Question 5: In Python, how can you convert a number to a string?
- str()
- enumerate()
- int()
- float()
Question 6: An Integer – int in Python can be converted to type Float by using the float function?
- True
- False
Question 7: What is the purpose of a break in a for loop in Python?
- The break statement will suspend the code until continue is run.
- To terminate the code
- It controls the flow of the loop and stops the current loop from executing any further.
- The break keywork is used to debug a for loop.
Question 8: An enumerate function is used to provide the index of the current iteration of a for loop.
- True
- False
Question 9: What will be the output of the code below:
a = isinstance(str, “aa”)
print(a)
- It will throw an error.
- “aa”
- False
- True
Question 10: Select all the valid input() formats among the following.
Select all that apply
- input()
- input(“”)
- name = input(“What is your name? “)
- “” = input(“My name is: ” + name)
Week 2: Programming in Python Coursera Quiz Answers
Quiz 1: Functions, loops and data structures
Question 1: What keyword is used to create a function in Python?
- var
- func
- def
- for
Question 2: What function in Python allows you to output data onto the screen?
- input()
- print()
- output()
- while
Question 3: A variable that is declared inside a function cannot be accessed from outside the function?
- True
- False
Question 4: Which of the declarations is correct when creating a for loop?
- for while in:
- for x in items:
- for in items:
- for if in items:
Question 5: What error will be thrown from the below code snippet?
nums = 34
for i in nums:
print(i)
- Exception
- MemoryError
- TypeError: ‘int’ object is not iterable
- FloatingPointError
Quiz 2: Knowledge check: Functions and Data structures
Question 1: The scope inside a function is referred to as?
- Global Scope
- Local Scope
- Outer Scope
- Built-in Scope
Question 2: Given the below list, what will be the output of the print statement be?
list_items = [10, 22, 45, 67, 90]
print(list_items[2])
- 22
- 10
- 45
- 67
Question 3: Which data structure type would be most suited for storing information that should not change?
- Dictionary
- List
- Tuple
Question 4: Which of the options below is not considered a built-in Python data structure?
- Set
- Tuple
- Tree
- Dictionary
Question 5: A Set in Python does not allow duplicate values?
- True
- False
Quiz 3: Exceptions in Python
Question 1: : What type of specific error will be raised when a file is not found?
- Exception
- FileNotFoundError
- BufferError
- ImportError
Question 2: Which of the following keywords are used to handle an exception?
- try again
- try except
- try def
- try catch
Question 3: Which of the following is the base class for all user-defined exceptions in Python?
- BaseException
- EOFError
- AssertionError
- Exception
Quiz 4: Read in data, store, manipulate and output new data to a file
Question 1: What function allows reading and writing files in Python?
- input()
- read_write()
- open()
- output()
Question 2: Which method allows reading of only a single line of a file containing multiple lines?
- readline()
- read()
- readlines()
- readall()
Question 3: What is the default mode for opening a file in python?
- read mode
- copy mode
- write mode
- read and write
Question 4: What is the difference between write and append mode?
- Nothing, they are both the same.
- Write mode overwrites the existing data. Append mode adds new data to the existing file.
- Write mode will append data to the existing file. Append will overwrite the data.
- Write mode will not allow edits if content already exists. Append mode will add new data to the file.
Question 5: What error is returned if a file does not exist?
- FileNotFoundError
- LookupError
- Exception
- AssertionError
Quiz 5: Module quiz: Basic Programming with Python
Question 1: Which of the following is not a sequence data-type in Python?
- Dictionary
- String
- List
- Tuples
Question 2: For a given list called new_list, which of the following options will work:
new_list = [1,2,3,4]
Select all that apply.
- new_list[4] = 10
- new_list.extend(new_list)
- new_list.insert(0, 0)
- new_list.append(5)
Question 3: Which of the following is not a type of variable scope in Python?
- Local
- Global
- Enclosing
- Package
Question 4: Which of the following is a built-in data structure in Python?
- Tree
- LinkedList
- Set
- Queue
Question 5: For a given file called ‘names.txt’, which of the following is NOT a valid syntax for opening a file:
- with open(‘names.txt’, ‘r’) as file: print(type(file))
- with open(‘names.txt’, ‘w’) as file: print(type(file))
- with open(‘names.txt’, ‘rb’) as file: print(type(file))
- with open(‘names.txt’, ‘rw’) as file: print(type(file))
Question 6: Which among the following is not a valid Exception in Python?
- ZeroDivisionException
- FileNotFoundError
- IndexError
- LoopError
Question 7: For a file called name.txt containing the lines below:
First line
Second line
And another !
with open('names.txt', 'r') as file:
lines = file.readlines()
print(lines)
- ‘First line’
- [‘First line\n’,
‘Second line\n’,
‘And another !’]
- [‘First line’]
- ‘First line’
‘Second line’
‘And another !’
Question 8: State TRUE or FALSE:
*args passed to the functions can accept the key-value pair.
- True
- False
Week 3: Programming in Python Coursera Quiz Answers
Quiz 1: Self-review: Make a cup of coffee
Question 1: True or False: While writing pseudocodes, we ideally put instructions for commands on the same line.
- True
- False
Question 2: What variable type would be best suited for determining if the kettle was boiling?
- float
- string
- boolean
- list
Question 3: Assuming milk and sugar are booleans and both are True. What conditional statement is correct for a user who wants both milk and sugar in their coffee?
- if milk or sugar:
- if milk and sugar:
- while milk and sugar:
- for milk and sugar:
Quiz 2: Knowledge check: Procedural Programming
Question 1: Which of the algorithm types below finds the best solution in each and every step instead of being overall optimal?
- Dynamic Programming
- Divide and conquer
- Greedy
- Recursive
Question 2: Which of the following Big O notations for function types has the slowest time complexity?
- O(log(n))
- O(c)
- O(n!)
- O(n^3)
Question 3: True or False: Linear time algorithms will always run under the same time and space regardless of the size of input.
- True
- False
Question 4: For determining efficiency, which of the following factors must be considered important?
- Time complexity
- Space complexity
- Neither of the two options above
- Both A and B
Quiz 3: Mapping key values to dictionary data structures
Question 1: What will be the output of the following code:
a = [[96], [69]]
print(”.join(list(map(str, a))))
- “[96][69]”
- “[96],[69]”
- [96][69]
- “9669”
Question 2: Which of the following is TRUE about the map() and filter() functions?
- Both the map() and filter() functions need to be defined before we use them.
- The map() function is built-in, but the filter() function needs to be defined first.
- Both the map() and filter() functions are built-in.
- The map() function needs to be defined first, but the filter() function is built-in.
Question 3: What will be the output of the following code:
z = ["alpha","bravo","charlie"]
new_z = [i[0]*2for i in z]
print(new_z)
- [‘aa’], [‘bb’], [‘cc’]
- [‘aa’, ‘bb’, ‘cc’]
- [‘a’, ‘b’, ‘c’]
- [‘alphaalpha’, ‘bravobravo’, ‘charliecharlie’]
Quiz 4: Knowledge check: Functional Programming
Question 1:
def sum(n):
if n == 1:
return 0
return n + sum(n-1)
a = sum(5)
print(a)
What will be the output of the recursive code above?
RecursionError: maximum recursion depth exceeded
- 0
- 15
- 14
Question 2: Statement A: A function in Python only executes when called.
Statement B: Functions in Python always returns a value.
- Both A and B are True
- B is True but A is False
- A is True but B is False
- Both A and B are False
Question 3:
some = ["aaa", "bbb"]
#1
def aa(some):
return
#2
def aa(some, 5):
return
#3
def aa():
return
#4
def aa():
return "aaa"
Which of the above are valid functions in Python? (Select all that apply)
- 2
- 4
- 1
- 3
Question 4: For the following code:
numbers = [15, 30, 47, 82, 95]
def lesser(numbers):
return numbers < 50
small = list(filter(lesser, numbers))
print(small)
If you modify the code above and change filter() function to map() function, what will be the list elements in the output that were not there earlier?
- 82, 95
- 15, 30, 47
- 15, 30, 47, 82, 95
- None of the other options
Quiz 5: Self-review: Define a Class
Question 1: Which of the following can be used for commenting a piece of code in Python?
Select all the correct answers.
- ( # ) – Hashtag
- ({ } ) – Curly braces
- ( @ ) – at sign
- (‘’’ ‘’’) – Triple quotations
Question 2: What will be the output of running the following code:
value = 7
class A:
value = 5
a = A()
a.value = 3
print(value)
- 3
- None
- 7
- 5
Question 3: What will be the output of the following code:
bravo = 3
b = B()
class B:
bravo = 5
print("Inside class B")
c = B()
print(b.bravo)
- No output
- 5
- 3
- Error
Question 4: Which of the following keywords allows the program to continue execution without impacting any functionality or flow?
- break
- skip
- pass
Quiz 6: Self-review: Instantiate a custom Object
Question 1: Were you able to complete the code and get the expected final output mentioned?
- Yes
- No
Question 2: What was the part that you were not able to complete? Specify the line numbers in the 8 lines of code.
The expected code for the program is as follows:
class MyFirstClass():
print("Who wrote this?")
index = "Author-Book"
def hand_list(self, philosopher, book):
print(MyFirstClass.index)
print(philosopher + " wrote the book: " + book)
whodunnit = MyFirstClass()
whodunnit.hand_list("Sun Tzu", "The Art of War")
- 5
- 6
- 8
- 3
- None
- 7
- 1
- 2
- 4
Question 3: Which of the following is the class variable in the code above?
- MyFirstClass
- index
- philosopher
- whodunnit
Question 4: How will you modify the code below if you want to include a “year” of publication in the output?
class MyFirstClass():
print("Who wrote this?")
index = "Author-Book"
def hand_list(self, philosopher, book):
print(MyFirstClass.index)
print(philosopher + " wrote the book: " + book)
whodunnit = MyFirstClass()
whodunnit.hand_list("Sun Tzu", "The Art of War")
Answer:
Modify line numbers 4, 6 and 8 such as:
def hand_list(self, philosopher, book, year):
print(philosopher + ” wrote the book: ” + book + “in the year ” + year)
whodunnit.hand_list(“Sun Tzu”, “The Art of War”, “5th century BC”)
Quiz 7: Abstract classes and methods
Question 1: Which of the following is not a requirement to create an abstract method in Python?
- Use of a decorator called abstractmethod
- A function called ABC
- Function called abstract
- A module called abc
Question 2: There is a direct implementation of Abstraction in Python.
- True
- False
Question 3: Which OOP principle is majorly used by Python to perform Abstraction?
- Polymorphism
- Inheritance
- Encapsulation
- Method Overloading
Question 4: Which of the following statements about abstract classes is true?
- Abstract classes inherit from other base classes.
- Abstract classes act only as a base class for other classes to derive from.
- Abstract classes help redefine the objects derived from them in a derived class.
- Abstract classes are used to instantiate abstract objects.
Question 5: True or False: Abstract classes cannot exist without Abstract methods present inside them.
- True
- False
Quiz 8: Self-review: Working with Methods
Question 1: True or False: A class can serve as a base class for many derived classes.
- True
- False
Question 2: In case of multiple inheritance where C is a derived class inheriting from both class A and B, and where a and b are the respective objects for these classes, which of the following code will inherit the classes A and B correctly? (Select all that apply)
- class(a, B)
- class C(B, A)
- class C(A, B)
- class (a, b)
Question 3: In Example 3 of the previous exercise, if we had modified the code to include a global variable ‘a = 5’ as follows:
a = 5
class A:
a = 7
pass
class B(A):
pass
class C(B):
pass
c = C()
print(c.a())
Will the code work and what will be the output if it does?
- Yes and it will print the value 5
- No
- Yes and it will print the value 7
Question 4: What function can be used other than mro() to see the way classes are inherited in a given piece of code?
- dir()
- class()
- info()
- help()
Question 5: The super() function is used to? (Select all that apply)
- call child class __init__()
- call different parent class method
- called over the __init__() method of the class it is called from
Question 6: What is the type of inheritance in the code below:
class A():
pass
class B(A):
pass
class C(B):
pass
- Multi-level
- Hierarchical
- Single
- Multiple
Quiz 9: Module quiz: Programming Paradigms
Question 1: Which of the following can be used for commenting a piece of code in Python?
- (‘’’ ‘’’) – Triple quotation marks
- ( @ ) – At the rate sign
- · ( # ) – Hashtag *
- ({ }) – Curly Brackets
Question 2: What will be the output of running the following code?
value = 7
class A:
value = 5
a = A()
a.value = 3
print(value)
- 5
- None of the above
- 3
- 7
Question 3: What will be the output of running the following code?
bravo = 3
b = B()
class B:
bravo = 5
print("Inside class B")
c = B()
print(b.bravo)
- Error
- None
- 5
- 3
Question 4: Which of the following keywords allows the program to continue execution without impacting any functionality or flow?
- break
- continue
- skip
- pass
Question 5: Which of the following is not a measure of Algorithmic complexity?
- Logarithmic Time
- Execution time
- Exponential Time
- Constant time
Question 6: Which of the following are the building blocks of Procedural programming?
- Objects and Classes
- Procedures and functions
- Variables and methods
- All of the options.
Question 7: True or False: Pure functions can modify global variables.
- True
- False
Question 8: Which of the following is an advantage of recursion?
- Easier to follow
- Recursive code can make your code look neater
- Easy to debug
- Recursion is memory efficient
Week 4: Programming in Python Coursera Quiz Answers
Quiz 1: Knowledge check: Modules
Question 1: Assuming there exists a module called ‘numpy’ with a function called ‘shape’ inside it, which of the following is NOT a valid syntax for writing an import statement? (Select all that apply)
- from numpy import *
- import shape from numpy
- import * from numpy
- import numpy as dn
- from numpy import shape as s
Question 2: Which of the following locations does the Python interpreter search for modules by default?
- PYTHONPATH or simply the environment variable that contains list of directories
- The current working directory
- Any user-specified location added to the System path using sys package
- Installation-dependent default directory
Question 3: We can import a text file using the import statement in Python:
- True
- False
Question 4: Which of the following statements is NOT true about the reload() function?
- You can use the reload() function multiple times for the same module in the given code.
- The reload() function can be used for making dynamic changes within code.
- The reload() function can be used to import modules in Python.
- You need to import a module before the reload() function can be used over it.
Question 5: Which of the following is NOT to be considered as an advantage of modular programming while using Python?
- Scope
- Reusability
- Simplicity
- Security
Question 6: Which of the following module types are directly available for import without any additional installation when you begin writing our code in Python? (Select all that apply)
- Modules in the current working directory of the Project
- Third-party packages from Python Package Index not present on the device
- User-defined modules in Home directory of the device
- Built-in modules
Quiz 2: Knowledge check: Popular Packages, Libraries and Frameworks
Question 1: Which of these is a popular package that is NOT primarily used in Web development?
- Django
- Scikit-learn
- Flask
- Pyramid
Question 2: Which of these packages can be applied in the field of Machine learning and Deep learning?
Select all the correct answers.
- PyTorch
- Pytest
- Keras
- Django
- TensorFlow
Question 3: Which of the following is not a type of web framework architecture?
- Asynchronous
- Microframework
- Synchronous
- Full-stack
Question 4: Pandas library in Python cannot be used for which of the following tasks?
- Visualisation such as graphs and charts.
- Cleaning, analyzing and maintaining data.
- Comparison of different columns in a table.
Question 5: Which of the following is not a built-in package in the Python standard library?
- os
- numpy
- math
- sys
- json
Quiz 3: Testing quiz
Question 1: State whether the following statement is True or False:
“Integration testing is where the application or software is tested as a whole and tested against the set requirements and expectations to ensure completeness”
- True
- False
Question 2: Which of the following is NOT primarily one of the four levels in testing?
- System testing
- Regression testing
- Unit testing
- Acceptance testing
- Integration testing
Question 3: Which of the following can be considered a valid testing scenario? (Select all that apply.)
- Broken links and images should be checked before loading a webpage
- Check for negative value acceptance in numeric field
- If the webpage resizes appropriately according to the device in use
- Deletion or form updation should request confirmation
Question 4: What can be considered as an ideal testing scenario?
- Using the minimal number of testing tools to find defects.
- Designing test cases in the shortest amount of time.
- Finding the maximum bugs and errors.
- Writing the least number of tests to find largest number of defects.
Question 5: Which job roles are not always a part of the testing lifecycle working on an application or product?
- Project Manager
- Programmers other than tester
- Tester
- Stakeholder
Quiz 4: Module quiz: Modules, packages, libraries and tools
Question 1: Which of the following is not true about Test-driven development?
- It ensures that the entire code is covered for testing.
- The process can also be called Red-Green refactor cycle.
- Test-driven development can only have one cycle of testing and error correction.
- In TDD, the requirements and standards are highlighted from the beginning.
Question 2: Which of the following is a built-in package for testing in Python?
- Selenium
- Robot Framework
- PyTest
- Pyunit or Unittest
Question 3: Which of the following is an important keyword in Python used for validation while doing Unit testing?
- yield
- assert
- async
- lambda
Question 4: Which of the following ‘V’s’ is not identified as a main characteristic of Big Data?
- Velocity
- Variability
- Volume
- Variety
Question 5: What will be the output of the following piece of code:
from math import pi
print(math.pi)
- There will be no output
- ImportError: No module named math
- 3.141592653589793
- NameError: name ‘math’ is not defined
Question 6: Which of the following is NOT primarily a package used for Image processing or data visualization?
- Matplotlib
- OpenCV
- Seaborn
- Scrapy
Question 7: _______ is/are the default package manager(s) for installing packages in Python.
- Python Package Index (pypi)
- pip
- Python Standard Library
- Built-in Module
Question 8: If you are working on some codeblock, which of the following can be ‘imported’ in it from external source?
Select all that apply.
- Variables
- Modules
- Packages
- Functions
Week 5: Programming in Python Coursera Quiz Answers
Quiz: End-of-Course Graded Assessment: Using Python
Question 1: Python is an interpreted language. Which of the following statements correctly describes an interpreted language?
- Python will save all code first prior to running.
- The source code is pre-built and compiled before running.
- The source code is converted into bytecode that is then executed by the Python virtual machine.
- Python needs to be built prior to it being run.
Question 2: Why is indentation important in Python?
- The code will compile faster with indentation.
- Python used indentation to determine which code block starts and ends.
- It makes the code more readable.
- The code will be read in a sequential manner
Question 3: What will be the output of the following code?
names = ["Anna", "Natasha", "Mike"]
names.insert(2, "Xi")
print(names)
- [“Anna”, “Natasha”, “Xi”, “Mike”]
- [“Anna”, “Natasha”, 2, “Xi”, “Mike”]
- [“Anna”, “Xi”, ”Mike” ]
- [“Anna”, “Natasha”, Xi]
Question 4: What will be the output of the code below?
for x in range(1, 4):
print(int((str((float(x))))))
- 1.0, 2.0
- 1 , 2
- “one”, “two”
- Will give an error
Question 5: What will be the output of the following code:
sample_dict = {1: 'Coffee', 2: 'Tea', 3: 'Juice'}
for x in sample_dict:
print(x)
- {1 2 3}
- (1, ‘Coffee’)
(2, ‘Tea’)
(3, ‘Juice’)
- ‘Coffee’, ‘Tea’, ‘Juice’
- 1 2 3
Question 6: What will be the output of the recursive code below?
def recursion(num):
print(num)
next = num - 3
if next > 1:
recursion(next)
recursion(11)
- 2 5 8 11
- 11 8 5 2
- 2 5 8
- 8 5 2
Question 7: What will be the type of time complexity for the following piece of code:
- Logarithmic Time
- Constant Time
- Quadratic Time
- Linear Time
Question 8: What will be the output of the code below:
str = 'Pomodoro'
for l in str:
if l == 'o':
str = str.split()
print(str, end=", ")
- ‘P’, ‘m’, ‘d’, ‘o’]
- Will throw an error
- [‘Pomodoro’, ‘modoro’, ‘doro‘, ‘ro’]
- [‘Pomodoro’]
Question 9: Find the output of the code below:
def d():
color = "green"
def e():
nonlocal color
color = "yellow"
e()
print("Color: " + color)
color = "red"
color = "blue"
d()
- red
- green
- blue
- yellow
Question 10: Find the output of the code below:
num = 9
class Car:
num = 5
bathrooms = 2
def cost_evaluation(num):
num = 10
return num
class Bike():
num = 11
cost_evaluation(num)
car = Car()
bike = Bike()
car.num = 7
Car.num = 2
print(num)
- 2
- 9
- 10
- 5
Question 11: Which of the following is the correct implementation that will return True if there is a parent class P, with an object p and a sub-class called C, with an object c?
- print(issubclass(P,C))
- print(issubclass(C,P))
- print(issubclass(C,c))
- print(issubclass(p,C))
Question 12: Django is a type of:
- Full-stack framework
- Micro-framework
- Asynchronous framework
Question 13: Which of the following is not true about Integration testing:
- Tests the flow of data from one component to another.
- It is where the application is tested as a whole.
- Primarily dealt by the tester.
- It combines unit tests.
Question 14: While using pytest for testing, it is necessary to run the file containing the main code before we can run the testing file containing our unit tests.
- False
- True
Question 15: What will be the output of the code below:
class A:
def a(self):
return "Function inside A"
class B:
def a(self):
return "Function inside B"
class C:
pass
class D(C, A, B):
pass
d = D()
print(d.a())
- Function inside A
- None of the above
- Function inside B
- No output
Get All Weeks Meta Database Engineer Professional Certificate
Introduction to Databases Coursera Quiz Answers
Version Control Coursera Quiz Answers
Database Structures and Management with MySQL Quiz Answers
Advanced MySQL Topics Coursera Quiz Answers
Programming in Python Coursera Quiz Answers
Database Clients Coursera Quiz Answers
Advanced Data Modeling Coursera Quiz Answers