Programming in Python Coursera Quiz Answers

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?

View
Yes

Question 2: In Python, what symbol is used for comments in code?

View
#

Question 3: What type will be assigned to the following variable: x = 4?

View
int – Integer

Question 4: Python allows for both implicit and explicit data type conversions?

View
True

Question 5: A variable called name is assigned the value of “Testing”. What will the output of the following equal – print(len(name));

View
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.

View
True

Question 2: The enumerate function is used to provide the index of the current iteration of a for a loop.

View
True

Question 3: A break statement can be used to exit out of a for loop based on a certain condition being satisfied.

View
True

Quiz 3: Module quiz: Getting Started with Python

Question 1: Python is a dynamically typed language. What does this mean?

View
Python does not require a type for a variable declaration. It automatically assigns the data type at run time.

Question 2: How do you create a block in Python?

View
A block is created using a colon followed by a new line and indentation

Question 3: When declaring a variable in Python, can a variable name contain white space?

View
No

Question 4: How can a variable be deleted in python?

View
The del keyword

Question 5: In Python, how can you convert a number to a string?

View
str()

Question 6: An Integer – int in Python can be converted to type Float by using the float function?

View
True

Question 7: What is the purpose of a break in a for loop in Python?

View
It controls the flow of the loop and stops the current loop from executing any further.

.

Question 8: An enumerate function is used to provide the index of the current iteration of a for loop.

View
True

Question 9: What will be the output of the code below:

a = isinstance(str, “aa”)

print(a)

View
It will throw an error. 

Question 10: Select all the valid input() formats among the following.

Select all that apply

View
1. input(“”)
2.name = input(“What is your 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?

View
def

Question 2: What function in Python allows you to output data onto the screen?

View
print()

Question 3: A variable that is declared inside a function cannot be accessed from outside the function?

View
True

Question 4: Which of the declarations is correct when creating a for loop?

View
for x in items:

Question 5: What error will be thrown from the below code snippet?

View
TypeError: ‘int’ object is not iterable
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?

View
Local Scope

Question 2: Given the below list, what will be the output of the print statement be?

View
45
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?

View
Tuple

Question 4: Which of the options below is not considered a built-in Python data structure?

View
Tree

Question 5: A Set in Python does not allow duplicate values?

View
True

Quiz 3: Exceptions in Python

Question 1: : What type of specific error will be raised when a file is not found?

View
FileNotFoundError

Question 2: Which of the following keywords are used to handle an exception?

View
try except

Question 3: Which of the following is the base class for all user-defined exceptions in Python?

View
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?

View
open()

Question 2: Which method allows reading of only a single line of a file containing multiple lines?

View
readline()

Question 3: What is the default mode for opening a file in python?

View
read mode

Question 4: What is the difference between write and append mode?

View
Write mode overwrites the existing data. Append mode adds new data to the existing file.

Question 5: What error is returned if a file does not exist?

View
FileNotFoundError

Quiz 5: Module quiz: Basic Programming with Python

Question 1: Which of the following is not a sequence data-type in Python?

View
Dictionary

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.

View
1.new_list[4] = 10
2.new_list.insert(0, 0)
3.new_list.append(5)

Question 3: Which of the following is not a type of variable scope in Python?

View
Package

Question 4: Which of the following is a built-in data structure in Python?

View
Set

Question 5: For a given file called ‘names.txt’, which of the following is NOT a valid syntax for opening a file:

View
with open(‘names.txt’, ‘rb’) as file: print(type(file))

Question 6: Which among the following is not a valid Exception in Python?

View
LoopError

Question 7: For a file called name.txt containing the lines below:

View
1.’First line’
[‘First line\n’,
‘Second line\n’,
‘And another !’] [‘First line’] First line’

[‘First line’] ‘First line’
‘Second line’
‘And another !’

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.

View
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.

View
False

Question 2: What variable type would be best suited for determining if the kettle was boiling?

View
boolean

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?

View
if 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?

View
Greedy

Question 2: Which of the following Big O notations for function types has the slowest time complexity?

View
O(n!)

Question 3: True or False: Linear time algorithms will always run under the same time and space regardless of the size of input.

View
False

Question 4: For determining efficiency, which of the following factors must be considered important?

View
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))))

View
“[96][69]”

Question 2: Which of the following is TRUE about the map() and filter() functions?

View
Both the map() and filter() functions are built-in.

Question 3: What will be the output of the following code:

View
[‘aa’, ‘bb’, ‘cc’]
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

View
14

Question 2: Statement A: A function in Python only executes when called.

Statement B: Functions in Python always returns a value.

View
A is True but B is 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)

View
1.4
2.1
3.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?

View
15, 30, 47

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.

View
1.( # ) – Hashtag
2.(‘’’ ‘’’) – Triple quotations

Question 2: What will be the output of running the following code:

View
7
value = 7
class A:
    value = 5
a = A()
a.value = 3
print(value)

Question 3: What will be the output of the following code:

View
Error
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?

View
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?

View
​Yes

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:

View
5

​6

​8

​3

None

​7

​1

​2

​4

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?

View
index

Question 4: How will you modify the code below if you want to include a “year” of publication in the output?

View
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”)

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?

View
Function called abstract

Question 2: There is a direct implementation of Abstraction in Python.

View
False

Question 3: Which OOP principle is majorly used by Python to perform Abstraction?

View
Inheritance

Question 4: Which of the following statements about abstract classes is true?

View
Abstract classes act only as a base class for other classes to derive from.

Question 5: True or False: Abstract classes cannot exist without Abstract methods present inside them.

View
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.

View
True

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)

View
1.class C(B, A)
2.class C(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?

View
No

Question 4: What function can be used other than mro() to see the way classes are inherited in a given piece of code?

View
help()

Question 5: The super() function is used to? (Select all that apply)

View
1.call child class __init__()
2.called over the __init__() method of the class it is called from

Question 6: What is the type of inheritance in the code below:

View
Multi-level
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?

View
1.(‘’’ ‘’’) – Triple quotation marks
2.· ( # ) – Hashtag *

Question 2: What will be the output of running the following code?

View
7
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?

View
Error
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?

View
pass

Question 5: Which of the following is not a measure of Algorithmic complexity?

View
Exponential Time

Question 6: Which of the following are the building blocks of Procedural programming?

View
Procedures and functions

Question 7: True or False: Pure functions can modify global variables.

View
True

Question 8: Which of the following is an advantage of recursion?

View
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)

View
1.import shape from numpy
2.import * from numpy

Question 2: Which of the following locations does the Python interpreter search for modules by default?

View
Any user-specified location added to the System path using sys package

Question 3: We can import a text file using the import statement in Python:

View
False

Question 4: Which of the following statements is NOT true about the reload() function?

View
The reload() function can be used to import modules in Python.

Question 5: Which of the following is NOT to be considered as an advantage of modular programming while using Python?

View
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)

View
1.Modules in the current working directory of the Project
2.Built-in modules

Question 1: Which of these is a popular package that is NOT primarily used in Web development?

View
Scikit-learn

Question 2: Which of these packages can be applied in the field of Machine learning and Deep learning?

Select all the correct answers.

View
1.PyTorch
2.Keras
3.TensorFlow

Question 3: Which of the following is not a type of web framework architecture?

View
Synchronous

Question 4: Pandas library in Python cannot be used for which of the following tasks?

View
Visualisation such as graphs and charts.

Question 5: Which of the following is not a built-in package in the Python standard library?

View
numpy

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”

View
True

Question 2: Which of the following is NOT primarily one of the four levels in testing?

View
Regression testing

Question 3: Which of the following can be considered a valid testing scenario? (Select all that apply.)

View
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

Question 4: What can be considered as an ideal testing scenario?

View
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?

View
Stakeholder

Quiz 4: Module quiz: Modules, packages, libraries and tools

Question 1: Which of the following is not true about Test-driven development?

View
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.

Question 2: Which of the following is a built-in package for testing in Python?

View
1.Selenium
2.Robot Framework
3.PyTest
4.Pyunit or Unittest

Question 3: Which of the following is an important keyword in Python used for validation while doing Unit testing?

View
1.yield
2.assert
3.async
4.lambda

Question 4: Which of the following ‘V’s’ is not identified as a main characteristic of Big Data?

View
1.Velocity
2.Variability
3.Volume
4.Variety

Question 5: What will be the output of the following piece of code:

View
1.There will be no output
2.ImportError: No module named math
3.3.141592653589793
4.NameError: name ‘math’ is not defined
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?

View
1.Matplotlib
2.OpenCV
3.Seaborn
4.Scrapy

Question 7: _______ is/are the default package manager(s) for installing packages in Python.

View
1.Python Package Index (pypi)
2.pip
3.Python Standard Library
4.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.

View
1.Variables
2.Modules
3.Packages
4.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?

View
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.

Question 2: Why is indentation important in Python?

View
Python used indentation to determine which code block starts and ends.

Question 3: What will be the output of the following code?

View
[“Anna”, “Natasha”, “Xi”, “Mike”]
names = ["Anna", "Natasha", "Mike"]
names.insert(2, "Xi")
print(names)

Question 4: What will be the output of the code below?

View
Will give an error
for x in range(1, 4):
    print(int((str((float(x))))))

Question 5: What will be the output of the following code:

View
1.‘Coffee’, ‘Tea’, ‘Juice’
1 2 3
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?

View
11 8 5 2
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:

View
James P. Grant
  • Logarithmic Time
  • Constant Time
  • Quadratic Time
  • Linear Time

Question 8: What will be the output of the code below:

View
Will throw an error
str = 'Pomodoro'
for l in str:
if l == 'o':
    str = str.split()
    print(str, end=", ")

Question 9: Find the output of the code below:

View
yellow
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:

View
9
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?

View
1.print(issubclass(P,C))
2.print(issubclass(C,P))
3.print(issubclass(C,c))
4.print(issubclass(p,C))

Question 12: Django is a type of:

View
Full-stack framework

Question 13: Which of the following is not true about Integration testing:

View
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.

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.

View
True

Question 15: What will be the output of the code below:

View
Function inside A
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

Team Networking Funda
Team Networking Funda

We are Team Networking Funda, a group of passionate authors and networking enthusiasts committed to sharing our expertise and experiences in networking and team building. With backgrounds in Data Science, Information Technology, Health, and Business Marketing, we bring diverse perspectives and insights to help you navigate the challenges and opportunities of professional networking and teamwork.

Leave a Reply

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