Introduction to Python Final Exam Answers | Saylor Academy

Hello Peers, Today we are going to share all quizzes answers of Introduction to Python Free Certification Course launched by Saylor Academy for totally free of cost✅✅✅. This is a certification course for every interested student.

Here, you will find Introduction to Python Exam Answers in Bold Color which are given below.

Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.

About this course –

This course uses the Python 3 programming language to introduce essential programming principles. Python 3 is a high-level interpreted language with several advantages, including syntax that is simple to understand and write and strong libraries that provide functionality. Even while Python 3 is a fantastic programming language for beginners, it is also widely utilized in engineering and data science applications. This course is designed for people who have never programmed before or have very little programming expertise. Data types, control flow, functions, file operations, and object-oriented programming are among the subjects covered. When you’ve completed this course.

Saylor Academy CS105: Introduction to Python Final Exam Answers

Question1: What will happen when these two commands are executed in the command line window?

> a=4

> type(a)

  • a.The number 4 will be echoed to the screen
  • b.The character a will be echoed to the screen
  • c.<class ‘int’> will be echoed to the screen
  • d.An error will occur because type is not a valid command

Question 2: What number will be echoed to the screen when this command is executed in the command line window?

> float(int(float(0.0034e3)))

  • a.34
  • b.3.0
  • c.3.4
  • d.34.0

Question 3: Which of the following commands will reassign the variable b by adding the number 5 to b?

  • a.5=b+b
  • b.b=b+5
  • c.b=b*5
  • d.b+5=b

Question 4: What will be printed to the screen when these commands are executed in the command line window?

> a=25

> b=30

> a=5*a

> b=b-10

> print(‘value 1 =’,a,’, value 2 =’,b)

  • a.’value 1 = 25 , value 2 = 30′
  • b.’value 1 = 125 , value 2 = 20′
  • c.’value 1 = 140 , value 2 = 150′
  • d.’value 1 = 150 , value 2 = 140′

Question 5: What will be printed to the screen when these commands are executed in the command line window?

> s=’abcdefghij’

> t=’vwyz’

> print(t+s[0])

  • a.213
  • b.’vwyza’
  • c.’t+s[0]’
  • d.’vawayaza’

Question 6: Given two variables x and y of type int, which of the following is a valid expression that is equivalent to x!=y?

  • a.x == not y
  • b.x>y or x<y
  • c.x not == y
  • d.x>y and x<y

Question 7: When using expressions that contain a mixture of relational operators and logical operators, which of the following is true?

  • a.The logical operators are disregarded
  • b.The relational operators are disregarded
  • c.Logical operators have higher precedence than relational operators
  • d.Relational operators have higher precedence than logical operators

Question 8: What is the output of this code snippet if it is executed using the run window?





  • a.1
  • b.1.5
  • c.True
  • d.False

Question 9: Assume this set of instructions is executed in the run window.


z=input(‘Enter your first name: ‘)



Which of the following would the variable z be considered?

  • a.An empty string
  • b.A user input variable
  • c.A variable of type int
  • d.A programmer-initialized variable

Question 10: Assume this set of instructions is executed in the run window.

z=intinput(‘Input a number: ‘))



What will be the resulting output?

  • a.The string ‘z12’
  • b.12 times the value input into the variable z
  • c.z copies of ’12’ will be concatenated together and output
  • d.An error, because the print expression mixes a string with a numeric value

Question 11: What will the output be after this set of instructions executes?




if (x<=2) and (y>3):


elif (x<=2) and (y==3):


elif (x==2) and (y>=3):




  • a.1
  • b.2
  • c.3
  • d.4

Question 12: If the value of c in this code snippet were to be changed:




for k in range(a,b,c):

    if k==10:


which of the following choices would not cause the value of 10 to be output?

  • a.c=2
  • b.c=4
  • c.c=8
  • d.c=10

Question 13: Which of the following can the ‘continue’ instruction be useful for?

  • a.Stopping a program from terminating
  • b.Disregarding a variable assignment within a loop
  • c.Allowing a program to continue when an input error occurs
  • d.Skipping over a set of commands within a loop and beginning the next iteration

Question 14: Which of the following can be used to refer to specific values contained within a list?

  • a.Container
  • b.Index
  • c.Operator
  • d.Sequence

Question 15: Given this code snippet:


for i in range(5):

    a.append(#fill in your expression here)


which of the following definitions of the variable a will generate the output

[2, 2, 3, 5, 8, 12]


  • a.a.append(i+i)
  • b.a.append(a[i]+i)
  • c.a.append(a[i]-i)
  • d.a.append(a[i]+2*i)

Question 16: Given the list:


what output would the instruction:



  • a.-1
  • b.8
  • c.[8, 7, 6, 5, -4, -3, -2, -1]
  • d.An error, because a negative index has been used

Question 17: You want to plot the function y=2x. Why would this code be problematic?

import matplotlib.pyplot as plt

x=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]


  • a.The operation 2*x is invalid
  • b.plt is not an allowed object name
  • c.matplotlib cannot be used to plot functions
  • d.The list defined by x does not contain enough data

Question 18: How might this code snippet be improved?



for z in a:


  • a.By replacing the for loop with print(a)
  • b.By replacing the for loop with s=len(a)
  • c.By replacing the for loop with s=max(a)
  • d.By replacing the for loop with s=sum(a)

Question 19: Which punctuation mark must the definition line for a function must end with?

  • a.Colon
  • b.Comma
  • c.Period
  • d.Semicolon

Question 20: What will the output be after this code runs?

def listsum(alist,sval):


    for val in alist:

        if val>sval:


    return s





  • a.0
  • b.1
  • c.7
  • d.12

Question 21: Assume import math has been invoked and that n is a variable of type int.

def coslist(n):

    x=[ ]

    c=[ ]


    for u in range(n+1):



    return x,c

What is this function computing?

  • a.The cosine function over the interval 0 to pi
  • b.The cosine function over the interval 0 to 2*pi
  • c.The cosine function over the interval n to pi
  • d.The cosine function over the interval n to 2*pi

Question 22: Assuming import random has been invoked, what is the smallest possible value the variable x could be for this instruction?


  • a.-1e300
  • b.-1.0
  • c.0.0
  • d.1.0

Question 23: Why would this set of instructions not be allowed in Python?



  • a.Because tuples are not mutable
  • b.Because an index cannot be used to access tuple elements
  • c.Because tuple elements must be separated by a semi-colon
  • d.Because tuple elements must be contained within curly brackets, not parentheses

Question 24: Which of the following statements is true?

  • a.Sets are an ordered collection of elements and are mutable
  • b.Sets are an unordered collection of elements and are mutable
  • c.Sets are an ordered collection of elements and are not mutable
  • d.Sets are an unordered collection of elements and are not mutable

Question 25: Given the set of instructions




xdict={‘k1’: a, ‘k2’:b, ‘k3’: c}

which of the following statements are true?

  • a.xdict[‘k1’] refers to a set
  • b.xdict[‘k1’] refers to a tuple
  • c.xdict[‘k3’] refers to a se
  • d.xdict[‘k3’] refers to a tuple

Question 26: The goal of this function is to search for a key associated with an input value v given the input dictionary d:

def funcd(d, v):

    for #complete this for statement

        if d[key] == v:

            return key

     return dict()

Which of the following statements would accomplish this goal?

  • a.for d in key:
  • b.for v in key:
  • c.for key in v:
  • d.for key in d:

Question 27: When using the open instruction, which of the following modes is assumed as the default if a file handling mode is not provided?

  • a.a
  • b.r
  • c.r+
  • d.w

Question 28: What will the data type of the variable z be after this code runs?

f = open(‘example.txt’,’w’)



f = open(‘example.txt’)


  • a.float
  • c.list
  • d.str

Question 29: Which of the following segments of code is this code segment most similar to?

myfile = open(‘source.txt’)



a. myfile = open(‘source.txt’)

for line in myfile:print(myfile.readlines())


b. myfile = open(‘source.txt’)

for line in myfile:



c. myfile = open(‘source.txt’)

for line in myfile:



d. myfile = open(‘source.txt’)

for line in myfile:



Question 30: Assume that source.txt contains the data:







What will the screen output be after this code executes?

myfile = open(‘source.txt’)


for line in myfile:

    if a==int(line):




  • a.-3
  • b.2
  • c.7
  • d.8

Question 31: When attempting to match a pattern string against a list of strings, using the compile method in the re module will do which of the following?

  • a.Store the pattern to a file
  • b.Convert the pattern into machine code
  • c.Increase the efficiency of pattern matching
  • d.Enable pattern matching using other programming languages

Question 32: Which of the following regular expressions can be used to search a list of names where the name(s) to be found follows the pattern ‘FirstName MiddleInitial. LastName’?

  • a.’.[A-Z]\s’
  • b.’.\s[A-Z]’
  • c.'[A-Z]\.\s$’
  • d.'[A-Z]\.\s’

Question 33: Which of the following lines, when inserted into this code:

import re

def findstr(str_list):

    #insert code here

    regex = re.compile(pattern)

    for val in str_list:

        if regex.match(val):



would match the strings:

‘. abcd’

‘ABCD. ‘


  • a.pattern = ‘[A-Z]\.\s[a-z]*’
  • b.pattern = ‘[A-Z]*\.\s[a-z]’
  • c.pattern = ‘[A-Z]*\.\s[a-z]*’
  • d.pattern = ‘[A-Z]+\.\s[a-z]+’

Question 34: Which of the following is true about the ‘try-except’ block?

  • a.Multiple errors can be handled within a single ‘except’ block
  • b.Each ‘try’ block must be associated with exactly one ‘except’ block
  • c.The ‘except’ block will not execute unless the type of error is specified
  • d.An ‘else’ block must be included for handling the case where no error occurs

Question 35: If this set of instructions were to execute, what would be the most appropriate exception handler?


x=float(input(‘Input a number:’))

a.except NameError:


b.except TypeError:


c.except ArithmeticError:


d. except ValueError:


Question 36: Object-oriented programming uses methods for defining and accomplishing tasks. Which of the following does procedural programming use?

  • a.Dictionaries
  • b.Functions
  • c.Snippets
  • d.Variables

Question 37: If two different objects from the same class are instantiated, which of the following will be true?

  • a.Their methods must be different
  • b.They will have different attributes
  • c.Their data attributes can take on different values
  • d.They cannot both be used as inputs to a function

Question 38: Given this class definition for a sphere:

class Sphere:

    def __init__(self, r):


Which of the following method definitions would enable you to execute the commands:





  • a.def __ge__(self,other):
    return self.radius&gt;other.radius
  • b.def __geq__(self,other):
    return self.radius&gt;other.radius
  • c.def ge(self,other):
    return self.radius&gt;other.radius
  • d.def geq(self,other):
    return self.radius&gt;other.radius

Question 39: Complete the method named charsearch in the class definition for Listops that will search the object attribute xlist (a list of strings) and return the number of strings that begin with the input character sval.

For example, if xlist contains:

[‘asdf’, ‘dfgh’, ‘sdfg’, ‘sfghj’, ‘swertq’, ‘qtyiu’]

and sval is ‘s’, then the method should return a value of 3.


Question 40: Complete the function listprod so that it will compute the product of the elements contained in an input numerical list.

For example:



would result in a value of 2, and



would result in a value of -4.


def listprod(x):


    for i in x:


    return p

Question 41: Complete the function distprop that will verify the following distributive property for sets:



∪ indicates the union operation

∩ indicates the intersection operation

Using this function definition line:

def distprop(A,B,C):

First compute: A∪(B∩C)

Then compute: (A∪B)∩(A∪C)

If the two are equal, return True; otherwise, return False.


def distprop(A,B,C):

    if A.union(B.intersection(C)) == (A.union(B)).intersection(A.union(C)):

        return True


        return False

Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock