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?
[expand title=View Answer] Yes[/expand]
Question 2: In Python, what symbol is used for comments in code?
[expand title=View Answer] # [/expand]
Question 3: What type will be assigned to the following variable: x = 4?
[expand title=View Answer] int – Integer[/expand]
Question 4: Python allows for both implicit and explicit data type conversions?
[expand title=View Answer]True[/expand]
Question 5: A variable called name is assigned the value of “Testing”. What will the output of the following equal – print(len(name));
[expand title=View Answer] 7 [/expand]
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.
[expand title=View Answer] True[/expand]
Question 2: The enumerate function is used to provide the index of the current iteration of a for a loop.
[expand title=View Answer] True[/expand]
Question 3: A break statement can be used to exit out of a for loop based on a certain condition being satisfied.
[expand title=View Answer] True [/expand]
Quiz 3: Module quiz: Getting Started with Python
Question 1: Python is a dynamically typed language. What does this mean?
[expand title=View Answer] Python does not require a type for a variable declaration. It automatically assigns the data type at run time. [/expand]
Question 2: How do you create a block in Python?
[expand title=View Answer] A block is created using a colon followed by a new line and indentation[/expand]
Question 3: When declaring a variable in Python, can a variable name contain white space?
[expand title=View Answer] No [/expand]
Question 4: How can a variable be deleted in python?
[expand title=View Answer] The del keyword[/expand]
Question 5: In Python, how can you convert a number to a string?
[expand title=View Answer]str() [/expand]
Question 6: An Integer – int in Python can be converted to type Float by using the float function?
[expand title=View Answer] True [/expand]
Question 7: What is the purpose of a break in a for loop in Python?
[expand title=View Answer]It controls the flow of the loop and stops the current loop from executing any further. [/expand]
.
Question 8: An enumerate function is used to provide the index of the current iteration of a for loop.
[expand title=View Answer]True [/expand]
Question 9: What will be the output of the code below:
a = isinstance(str, “aa”)
print(a)
[expand title=View Answer] It will throw an error. [/expand]
Question 10: Select all the valid input() formats among the following.
Select all that apply
[expand title=View Answer]
1. input(“”)
2.name = input(“What is your name? “)
[/expand]
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?
[expand title=View Answer]def [/expand]
Question 2: What function in Python allows you to output data onto the screen?
[expand title=View Answer] print()[/expand]
Question 3: A variable that is declared inside a function cannot be accessed from outside the function?
[expand title=View Answer] True [/expand]
Question 4: Which of the declarations is correct when creating a for loop?
[expand title=View Answer] for x in items: [/expand]
Question 5: What error will be thrown from the below code snippet?
[expand title=View Answer] TypeError: ‘int’ object is not iterable [/expand]
nums = 34
for i in nums:
print(i)
Quiz 2: Knowledge check: Functions and Data structures
Question 1: The scope inside a function is referred to as?
[expand title=View Answer]Local Scope [/expand]
Question 2: Given the below list, what will be the output of the print statement be?
[expand title=View Answer] 45 [/expand]
list_items = [10, 22, 45, 67, 90]
print(list_items[2])
Question 3: Which data structure type would be most suited for storing information that should not change?
[expand title=View Answer] Tuple[/expand]
Question 4: Which of the options below is not considered a built-in Python data structure?
[expand title=View Answer] Tree [/expand]
Question 5: A Set in Python does not allow duplicate values?
[expand title=View Answer] True[/expand]
Quiz 3: Exceptions in Python
Question 1: : What type of specific error will be raised when a file is not found?
[expand title=View Answer] FileNotFoundError [/expand]
Question 2: Which of the following keywords are used to handle an exception?
[expand title=View Answer] try except[/expand]
Question 3: Which of the following is the base class for all user-defined exceptions in Python?
[expand title=View Answer] Exception [/expand]
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?
[expand title=View Answer] open() [/expand]
Question 2: Which method allows reading of only a single line of a file containing multiple lines?
[expand title=View Answer] readline()[/expand]
Question 3: What is the default mode for opening a file in python?
[expand title=View Answer] read mode [/expand]
Question 4: What is the difference between write and append mode?
[expand title=View Answer] Write mode overwrites the existing data. Append mode adds new data to the existing file. [/expand]
Question 5: What error is returned if a file does not exist?
[expand title=View Answer] FileNotFoundError[/expand]
Quiz 5: Module quiz: Basic Programming with Python
Question 1: Which of the following is not a sequence data-type in Python?
[expand title=View Answer] Dictionary[/expand]
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.
[expand title=View Answer]
1.new_list[4] = 10
2.new_list.insert(0, 0)
3.new_list.append(5)
[/expand]
Question 3: Which of the following is not a type of variable scope in Python?
[expand title=View Answer] Package [/expand]
Question 4: Which of the following is a built-in data structure in Python?
[expand title=View Answer] Set[/expand]
Question 5: For a given file called ‘names.txt’, which of the following is NOT a valid syntax for opening a file:
[expand title=View Answer]with open(‘names.txt’, ‘rb’) as file: print(type(file))[/expand]
Question 6: Which among the following is not a valid Exception in Python?
[expand title=View Answer]LoopError [/expand]
Question 7: For a file called name.txt containing the lines below:
[expand title=View Answer]
1.’First line’
[‘First line\n’,
‘Second line\n’,
‘And another !’]
[‘First line’]
First line’
[‘First line’]
‘First line’
‘Second line’
‘And another !’
[/expand]
First line
Second line
And another !
with open('names.txt', 'r') as file:
lines = file.readlines()
print(lines)
Question 8: State TRUE or FALSE:
*args passed to the functions can accept the key-value pair.
[expand title=View Answer] False [/expand]
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.
[expand title=View Answer]False [/expand]
Question 2: What variable type would be best suited for determining if the kettle was boiling?
[expand title=View Answer] boolean[/expand]
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?
[expand title=View Answer] if milk and sugar: [/expand]
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?
[expand title=View Answer] Greedy [/expand]
Question 2: Which of the following Big O notations for function types has the slowest time complexity?
[expand title=View Answer] O(n!) [/expand]
Question 3: True or False: Linear time algorithms will always run under the same time and space regardless of the size of input.
[expand title=View Answer] False[/expand]
Question 4: For determining efficiency, which of the following factors must be considered important?
[expand title=View Answer] Both A and B [/expand]
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))))
[expand title=View Answer] “[96][69]” [/expand]
Question 2: Which of the following is TRUE about the map() and filter() functions?
[expand title=View Answer] Both the map() and filter() functions are built-in. [/expand]
Question 3: What will be the output of the following code:
[expand title=View Answer][‘aa’, ‘bb’, ‘cc’] [/expand]
z = ["alpha","bravo","charlie"]
new_z = [i[0]*2for i in z]
print(new_z)
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
[expand title=View Answer] 14[/expand]
Question 2: Statement A: A function in Python only executes when called.
Statement B: Functions in Python always returns a value.
[expand title=View Answer] A is True but B is False [/expand]
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)
[expand title=View Answer]
1.4
2.1
3.3
[/expand]
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?
[expand title=View Answer]15, 30, 47 [/expand]
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.
[expand title=View Answer]
1.( # ) – Hashtag
2.(‘’’ ‘’’) – Triple quotations
[/expand]
Question 2: What will be the output of running the following code:
[expand title=View Answer] 7 [/expand]
value = 7
class A:
value = 5
a = A()
a.value = 3
print(value)
Question 3: What will be the output of the following code:
[expand title=View Answer]Error[/expand]
bravo = 3
b = B()
class B:
bravo = 5
print("Inside class B")
c = B()
print(b.bravo)
Question 4: Which of the following keywords allows the program to continue execution without impacting any functionality or flow?
[expand title=View Answer]pass [/expand]
Quiz 6: Self-review: Instantiate a custom Object
Question 1: Were you able to complete the code and get the expected final output mentioned?
[expand title=View Answer] Yes [/expand]
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:
[expand title=View Answer]
5
6
8
3
None
7
1
2
4
[/expand]
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")
Question 3: Which of the following is the class variable in the code above?
[expand title=View Answer] index[/expand]
Question 4: How will you modify the code below if you want to include a “year” of publication in the output?
[expand title=View 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”)
[/expand]
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")
Quiz 7: Abstract classes and methods
Question 1: Which of the following is not a requirement to create an abstract method in Python?
[expand title=View Answer] Function called abstract[/expand]
Question 2: There is a direct implementation of Abstraction in Python.
[expand title=View Answer] False[/expand]
Question 3: Which OOP principle is majorly used by Python to perform Abstraction?
[expand title=View Answer] Inheritance [/expand]
Question 4: Which of the following statements about abstract classes is true?
[expand title=View Answer] Abstract classes act only as a base class for other classes to derive from.[/expand]
Question 5: True or False: Abstract classes cannot exist without Abstract methods present inside them.
[expand title=View Answer]False [/expand]
Quiz 8: Self-review: Working with Methods
Question 1: True or False: A class can serve as a base class for many derived classes.
[expand title=View Answer] True[/expand]
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)
[expand title=View Answer]
1.class C(B, A)
2.class C(A, B)
[/expand]
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?
[expand title=View Answer]No[/expand]
Question 4: What function can be used other than mro() to see the way classes are inherited in a given piece of code?
[expand title=View Answer] help()[/expand]
Question 5: The super() function is used to? (Select all that apply)
[expand title=View Answer]
1.call child class __init__()
2.called over the __init__() method of the class it is called from
[/expand]
Question 6: What is the type of inheritance in the code below:
[expand title=View Answer] Multi-level [/expand]
class A():
pass
class B(A):
pass
class C(B):
pass
Quiz 9: Module quiz: Programming Paradigms
Question 1: Which of the following can be used for commenting a piece of code in Python?
[expand title=View Answer]
1.(‘’’ ‘’’) – Triple quotation marks
2.· ( # ) – Hashtag *
[/expand]
Question 2: What will be the output of running the following code?
[expand title=View Answer]7[/expand]
value = 7
class A:
value = 5
a = A()
a.value = 3
print(value)
Question 3: What will be the output of running the following code?
[expand title=View Answer] Error[/expand]
bravo = 3
b = B()
class B:
bravo = 5
print("Inside class B")
c = B()
print(b.bravo)
Question 4: Which of the following keywords allows the program to continue execution without impacting any functionality or flow?
[expand title=View Answer] pass [/expand]
Question 5: Which of the following is not a measure of Algorithmic complexity?
[expand title=View Answer] Exponential Time[/expand]
Question 6: Which of the following are the building blocks of Procedural programming?
[expand title=View Answer] Procedures and functions[/expand]
Question 7: True or False: Pure functions can modify global variables.
[expand title=View Answer] True[/expand]
Question 8: Which of the following is an advantage of recursion?
[expand title=View Answer] Recursion is memory efficient [/expand]
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)
[expand title=View Answer]
1.import shape from numpy
2.import * from numpy
[/expand]
Question 2: Which of the following locations does the Python interpreter search for modules by default?
[expand title=View Answer]Any user-specified location added to the System path using sys package[/expand]
Question 3: We can import a text file using the import statement in Python:
[expand title=View Answer]False [/expand]
Question 4: Which of the following statements is NOT true about the reload() function?
[expand title=View Answer]The reload() function can be used to import modules in Python.[/expand]
Question 5: Which of the following is NOT to be considered as an advantage of modular programming while using Python?
[expand title=View Answer] Security [/expand]
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)
[expand title=View Answer]
1.Modules in the current working directory of the Project
2.Built-in modules
[/expand]
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?
[expand title=View Answer] Scikit-learn[/expand]
Question 2: Which of these packages can be applied in the field of Machine learning and Deep learning?
Select all the correct answers.
[expand title=View Answer]
1.PyTorch
2.Keras
3.TensorFlow
[/expand]
Question 3: Which of the following is not a type of web framework architecture?
[expand title=View Answer] Synchronous [/expand]
Question 4: Pandas library in Python cannot be used for which of the following tasks?
[expand title=View Answer] Visualisation such as graphs and charts. [/expand]
Question 5: Which of the following is not a built-in package in the Python standard library?
[expand title=View Answer] numpy [/expand]
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”
[expand title=View Answer] True[/expand]
Question 2: Which of the following is NOT primarily one of the four levels in testing?
[expand title=View Answer] Regression testing [/expand]
Question 3: Which of the following can be considered a valid testing scenario? (Select all that apply.)
[expand title=View Answer]
1.Broken links and images should be checked before loading a webpage
2.Check for negative value acceptance in numeric field
3.If the webpage resizes appropriately according to the device in use
4.Deletion or form updation should request confirmation
[/expand]
Question 4: What can be considered as an ideal testing scenario?
[expand title=View Answer] Writing the least number of tests to find largest number of defects. [/expand]
Question 5: Which job roles are not always a part of the testing lifecycle working on an application or product?
[expand title=View Answer]Stakeholder[/expand]
Quiz 4: Module quiz: Modules, packages, libraries and tools
Question 1: Which of the following is not true about Test-driven development?
[expand title=View Answer]
1.It ensures that the entire code is covered for testing.
2.The process can also be called Red-Green refactor cycle.
3.Test-driven development can only have one cycle of testing and error correction.
4.In TDD, the requirements and standards are highlighted from the beginning.
[/expand]
Question 2: Which of the following is a built-in package for testing in Python?
[expand title=View Answer]
1.Selenium
2.Robot Framework
3.PyTest
4.Pyunit or Unittest
[/expand]
Question 3: Which of the following is an important keyword in Python used for validation while doing Unit testing?
[expand title=View Answer]
1.yield
2.assert
3.async
4.lambda
[/expand]
Question 4: Which of the following ‘V’s’ is not identified as a main characteristic of Big Data?
[expand title=View Answer]
1.Velocity
2.Variability
3.Volume
4.Variety
[/expand]
Question 5: What will be the output of the following piece of code:
[expand title=View Answer]
1.There will be no output
2.ImportError: No module named math
3.3.141592653589793
4.NameError: name ‘math’ is not defined
[/expand]
from math import pi
print(math.pi)
Question 6: Which of the following is NOT primarily a package used for Image processing or data visualization?
[expand title=View Answer]
1.Matplotlib
2.OpenCV
3.Seaborn
4.Scrapy
[/expand]
Question 7: _______ is/are the default package manager(s) for installing packages in Python.
[expand title=View Answer]
1.Python Package Index (pypi)
2.pip
3.Python Standard Library
4.Built-in Module
[/expand]
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.
[expand title=View Answer]
1.Variables
2.Modules
3.Packages
4.Functions
[/expand]
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?
[expand title=View Answer]
1.Python will save all code first prior to running.
2.The source code is pre-built and compiled before running.
3.The source code is converted into bytecode that is then executed by the Python virtual machine.
4.Python needs to be built prior to it being run.
[/expand]
Question 2: Why is indentation important in Python?
[expand title=View Answer] Python used indentation to determine which code block starts and ends. [/expand]
Question 3: What will be the output of the following code?
[expand title=View Answer] [“Anna”, “Natasha”, “Xi”, “Mike”] [/expand]
names = ["Anna", "Natasha", "Mike"]
names.insert(2, "Xi")
print(names)
Question 4: What will be the output of the code below?
[expand title=View Answer] Will give an error[/expand]
for x in range(1, 4):
print(int((str((float(x))))))
Question 5: What will be the output of the following code:
[expand title=View Answer]
1.‘Coffee’, ‘Tea’, ‘Juice’
1 2 3
[/expand]
sample_dict = {1: 'Coffee', 2: 'Tea', 3: 'Juice'}
for x in sample_dict:
print(x)
Question 6: What will be the output of the recursive code below?
[expand title=View Answer] 11 8 5 2 [/expand]
def recursion(num):
print(num)
next = num - 3
if next > 1:
recursion(next)
recursion(11)
Question 7: What will be the type of time complexity for the following piece of code:
[expand title=View Answer] James P. Grant [/expand]
- Logarithmic Time
- Constant Time
- Quadratic Time
- Linear Time
Question 8: What will be the output of the code below:
[expand title=View Answer] Will throw an error [/expand]
str = 'Pomodoro'
for l in str:
if l == 'o':
str = str.split()
print(str, end=", ")
Question 9: Find the output of the code below:
[expand title=View Answer]yellow[/expand]
def d():
color = "green"
def e():
nonlocal color
color = "yellow"
e()
print("Color: " + color)
color = "red"
color = "blue"
d()
Question 10: Find the output of the code below:
[expand title=View Answer]9 [/expand]
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)
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?
[expand title=View Answer]
1.print(issubclass(P,C))
2.print(issubclass(C,P))
3.print(issubclass(C,c))
4.print(issubclass(p,C))
[/expand]
Question 12: Django is a type of:
[expand title=View Answer]Full-stack framework [/expand]
Question 13: Which of the following is not true about Integration testing:
[expand title=View Answer]
1.Tests the flow of data from one component to another.
2.It is where the application is tested as a whole.
3.Primarily dealt by the tester.
4.It combines unit tests.
[/expand]
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.
[expand title=View Answer] True [/expand]
Question 15: What will be the output of the code below:
[expand title=View Answer] Function inside A[/expand]
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())
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