Home » CS105: Introduction to Python Certification Exam Answers

CS105: Introduction to Python Certification Exam Answers

by IndiaSuccessStories
0 comment

CS105: Introduction to Python Exam Quiz Answers

  • The number 4 will be echoed to the screen
  • The character a will be echoed to the screen
  • <class ‘int’> will be echoed to the screen
  • An error will occur because type is not a valid command
banner
  • z is of type str because it contains the character ‘e’
  • a is of type bool because it contains characters and numbers
  • a is of type int because the 5 is not followed by a decimal point
  • z is of type float because it is expressed using scientific notation
  • The number 1
  • The number 3
  • The number 4
  • The character ‘c’
  • ‘Value 1 = 20, value 2 = 20’
  • ‘Value 1 = 20, value 2 = 100’
  • ‘Value 1 = 100, value 2 = 20’
  • ‘Value 1 = 100, value 2 = 100’
  • 32
  • 32.0
  • ’32’
  • ‘32.0’
  • a*b
  • b*b*b
  • a*b*a*b
  • a*a*a*a*a
  • The logical operators are disregarded
  • The relational operators are disregarded
  • Logical operators have higher precedence than relational operators
  • Relational operators have higher precedence than logical operators
  • They can be initialized without user input
  • They must be initialized as a string data type
  • They must be initialized as a numerical data type
  • They cannot be changed after they have been assigned
  • A Boolean True will be generated
  • A Boolean False will be generated
  • An error will occur because this syntax is invalid
  • The alphabetical order of the two input characters will be compared
  • Stopping a program from terminating
  • Disregarding a variable assignment within a loop
  • Allowing a program to continue when an input error occurs
  • Skipping over a set of commands within a loop and beginning the next iteration
  • They are static
  • They are global
  • They are mutable
  • They are immutable
  • print(c)
  • for val in c:

print(val)

  • for i in range(7):

print(c[i])

  • for i in range(9):

print(c[i])

  • -1
  • 8
  • [8, 7, 6, 5, -4, -3, -2, -1]
  • An error, because a negative index has been used
  • A built-in function
  • A recyclable function
  • A procedural function
  • A user-defined function
  • Colon
  • Comma
  • Period
  • Semicolon
  • 0
  • 1
  • 7
  • 12
  • The cosine function over the interval 0 to pi
  • The cosine function over the interval 0 to 2*pi
  • The cosine function over the interval n to pi
  • The cosine function over the interval n to 2*pi
  • Because tuples are not mutable
  • Because an index cannot be used to access tuple elements
  • Because tuple elements must be separated by a semi-colon
  • Because tuple elements must be contained within curly brackets, not parentheses
  • Sets are an ordered collection of elements and are mutable
  • Sets are an unordered collection of elements and are mutable
  • Sets are an ordered collection of elements and are not mutable
  • Sets are an unordered collection of elements and are not mutable
  • {‘k1’, ‘k2’, ‘k3’}
  • {‘v1’, ‘v2’, ‘v3’}
  • {‘k1′,’v1’, ‘k2’, v2’, ‘k3′,’v3’}
  • {‘k1’: ‘v1’, ‘k2’: ‘v2’, ‘k3’: ‘v3’}
  • a
  • r
  • r+
  • w
  • f.write([1,2,3])
  • f.write(‘1 2 3’)
  • f.write(‘1′,’2′,’3’)
  • f.write([‘1′,’2′,’3’])
  • myfile = open(‘source.txt’)

for line in myfile:

line = line.rstrip()

a=line.split(‘ ‘)

print(a[0]*a[1])

myfile.close()

  • myfile = open(‘source.txt’)

for line in myfile:

line = line.rstrip()

a=float(line.split(‘ ‘))

print(a[0]*a[1])

myfile.close()

  • myfile = open(‘source.txt’)

for line in myfile:

line = line.rstrip()

a=line.split(‘ ‘)

print(int(a[0])*int(a[1]))

myfile.close()

  • myfile = open(‘source.txt’)

for line in myfile:

line = line.rstrip()

a=int(line.split(‘ ‘))

print(a[0]*a[1])

myfile.close()

  • pattern = ‘[A-Z]\.\s[a-z]*’
  • pattern = ‘[A-Z]*\.\s[a-z]’
  • pattern = ‘[A-Z]*\.\s[a-z]*’
  • pattern = ‘[A-Z]+\.\s[a-z]+’
  • Dictionaries
  • Functions
  • Snippets
  • Variables
  • A class is instance of an object
  • An object is an instance of class
  • A class cannot contain an object
  • The term ‘object’ is another name for a class
  • def __ge__(self,other):

return self.radius&gt;other.radius

  • def __geq__(self,other):

return self.radius&gt;other.radius

  • def ge(self,other):

return self.radius&gt;other.radius

  • def geq(self,other):

return self.radius&gt;other.radius

def listprod(input_list):

    result = 1  # Initialize the result to 1

    for num in input_list:

        result *= num  # Multiply each element with the result

    return result

def listchk(alist, n):

  1. KeyError exception handler should return a value of float(‘Nan’).
  2. Otherwise, the function should return the value associated withe the input key.

class Dictops:

    def __init__(self, xdict):

        self.xdict = xdict

    def keyvalsearch(self, key):

        try:

            value = self.xdict[key]

        except KeyError:

            value = float(‘nan’)

        return value

  • When it is written in scientific notation with a decimal point
  • When it is written in scientific notation without a decimal point
  • When it contains a decimal point with no digits following the decimal point
  • When it does not contain a decimal point and it is not written in scientific notation
  • 5=b+b
  • b=b+5
  • b=b*5
  • b+5=b
  • 35
  • 75
  • ‘d*c’
  • 77777
  • 213
  • ‘vwyza’
  • ‘t+s[0]’
  • ‘vawayaza’
  • b*b+d
  • c*b+d
  • c*c+d
  • d*b+c
  • No output, because the while loop does not execute
  • An error, because the variable i is not greater than 0
  • The while loop will print out integers starting at 0 in an infinite loop
  • The while loop will print out integers starting at 1 in an infinite loop
  • Halting the execution of a program
  • Changing a for loop into a while loop
  • Exiting a loop abruptly when a certain condition is met
  • Stopping the execution of the input instruction when invalid input is entered
  • The character ‘c’ appears within the list
  • The 6th element is ‘ghi’, which is a string
  • The maximum index allowed for this list is 5
  • The list mixes both numerical and string data
  • -2
  • -1
  • 0
  • 0.0
  • By changing the variable names
  • By using while loops instead of for loops
  • By using range(len(a)) instead of range (5)
  • By printing out the elements without using a loop
  • Parentheses
  • An equals sign
  • A return statements
  • A relational operator
  • c=a+b
  • c[i]=a[i]+b[i]
  • return a[i]+b[i]
  • c.append(a[i]+b[i])
  • math.exp
  • math.log
  • math.pow
  • math.log2
  • s must be less than 0
  • s must be greater than 100
  • s cannot exceed a value of 1
  • s cannot exceed a value of 100
  • They are separated by commas and contained within parentheses
  • They are separated by commas and contained within curly brackets
  • They are separated by semicolons and contained within parentheses
  • They are separated by commas and contained within square brackets
  • {2, 5, 6}
  • {2, 4, 6, 8}
  • {2, 4, 5, 6, 8}
  • {2, 4, 6, 8, 2, 5, 6}
  • 4
  • 7
  • ‘1’
  • ‘f’
  • a b c
  • d e f
  • a b c

d e f

  • a b c d e f
  • print(f.read())
  • print(f.read())

print(f.read())

  • print(f.readline()) 

print(f.readline())

  • print(f.readlines())
  • ‘. [A-Z] \s’
  • ‘.\s[A-Z]’
  • ‘[A-Z] \.\s$’
  • ‘[A-Z] \.\s’
  • Functions
  • ‘if’ statements
  • ‘for’ statements
  • ‘break’ statements
  • def init(self, r):

self.radius=r

  • def __init__(self, r):

self.radius=r

  • def __init__(r):

init.radius=r

  • def init(r):

init.radius=r

  1. ∪∪ indicates the union operation
  2.  indicates the intersection operation
  1. First compute: A(BC)(�∩�)
  2. Then compute: (AB)∩(AC)(��)∩(��)

def distprop(A, B, C):

    # Compute A (B ∩ C)

    left_side = A.union(B.intersection(C))

    # Compute (A B) ∩ (A C)

    right_side = (A.union(B)).intersection(A.union(C))

    # Check if the two sets are equal

    if left_side == right_side:

        return True

    else:

        return False

  • 34
  • 3.0
  • 3.4
  • 34.0
  • ‘Value 1 = 25, value 2 = 30’
  • ‘Value 1 = 125, value 2 = 20’
  • ‘Value 1 = 140, value 2 = 150’
  • ‘Value 1 = 150, value 2 = 140’
  • x == not y
  • x>y or x<y
  • x not == y
  • x>y and x<y
  • 0
  • 1
  • True
  • False
  • An empty string
  • A user input variable
  • A variable of type

int

  • A programmer-initialized variable
  • 1
  • 2
  • 3
  • 4
  • 0
  • 1
  • 20
  • 25
  • a [0:3]
  • a [0:4]
  • a [1:4]
  • a [1:5]
  • By replacing the for loop with print(a)
  • By replacing the for loop with s=len(a)
  • By replacing the for loop with s=max(a)
  • By replacing the for loop with s=sum(a)
  • 2.0
  • 3.0
  • 8.0
  • 10.0
  • -1e300
  • -1.0
  • 0.0
  • 1.0
  • {‘v1’: 1, ‘v2’: 23, ‘v3’: 3}
  • {‘v1’: 1, ‘v2’: 2, ‘v3’: 3, 1: ‘v1’, 2: 23, 3: ‘v3’}
  • {‘v1’: 1, ‘v2’: 23, ‘v3’: 3, 1: ‘v1’, 2: 23, 3: ‘v3’}
  • {‘v1’: 1, ‘v2’: 23, ‘v3’: 3, 1: ‘v1’, 2: ‘v2’, 3: ‘v3’}
  • 1 2 3
  • 4 5 6
  • 1 2 3

4 5 6

  • 1 2 3 4 5 6
  • [a,b]=f.read()
  • f.readline()

a=float(f.readline())

b=float(f.readline())

  • f.readline()

f.readline()

a=float(f.readline())

b=float(f.readline())

  • a=float(f.readline())

b=float(f.readline())

  • Anywhere within a list
  • At the beginning of a list
  • Anywhere within a string
  • At the beginning of a string
  • re_pattern(‘d123d123d123d123’, ‘d*’)
  • re_pattern(‘d123d123d123d123’, ‘\d’)
  • re_pattern(‘d123d123d123d123’, ‘\d+’)
  • re_pattern(‘d123d123d123d123’, ‘\D+’)
  • except NameError:

print(‘NameError’)

  • except TypeError:

print(‘TypeError’)

  • except ArithmeticError:

print(‘ArithmeticError’)

  • except ValueError:

print(‘ValueError’)

  • def __ge__(self,other):

return self.radius&gt;other.radius

  • def __geq__(self,other):

return self.radius&gt;other.radius

  • def ge(self,other):

return self.radius&gt;other.radius

  • def geq(self,other):

return self.radius&gt;other.radius

class Listops:

    def __init__(self, xlist):

        self.xlist = xlist

    def charsearch(self, sval):

        count = 0

        for string in self.xlist:

            if string.startswith(sval):

                count += 1

        return count

  • The number 4 will be echoed to the screen
  • The character a will be echoed to the screen
  • The number 4.0 will be echoed to the screen
  • An error will occur because the print(a) command was not used
  • The number 4
  • The number 9
  • The number 16
  • The character ‘b’
  • 12, because 2, 3, and 2 are multiplied together
  • 16, because exponentiation takes place before multiplication
  • 64, because multiplication takes place before exponentiation
  • An error, because ** is not a valid Python operation
  • 1
  • 1.5
  • True
  • False
  • <class ‘int’>
  • <class ‘bool’>
  • <class ‘float’>
  • An error, because == is comparing a str with an int
  • a<30
  • b<-20
  • c>0
  • c>=0
  • 0
  • 4
  • 5
  • 7
  • Container
  • Index
  • Operator
  • Sequence
  • xdict[‘k1’] refers to a set
  • xdict[‘k1’] refers to a tuple
  • xdict[‘k3’] refers to a set
  • xdict[‘k3’] refers to a tuple
  • The variable z will be a list
  • The variable z will be a tuple
  • z=list(atuple) will cause an error because tuples are immutable
  • atuple=(‘a’,’b’,5.7,9) will cause an error because the elements are not the same data type
  • cset=bset==aset
  • cset=bset!=aset
  • cset=bset.union(aset)
  • cset=bset.intersection(aset)
  • for line:
  • for line in myfile:
  • for myfile in line:
  • for line in range(myfile):
  • Define a new method within an existing class
  • Instantiate multiple objects from an existing class
  • Overload an existing method within an existing class
  • Define a new class that is a modified version of an existing class
  • ‘y and z are considered to be large cities’
  • ‘z and y are considered to be large cities’
  • ‘Chicago and London are considered to be large cities’
  • ‘London and Chicago are considered to be large cities’
  • if x<0 or y<3:
  • if x<0 or y>3:
  • elif z==1 or y<-1:
  • elif z>=1 or y>-1:
  • c=2
  • c=4
  • c=8
  • c=10
  • a.append(i+i)
  • a.append(a[i]+i)
  • a.append(a[i]-i)
  • a.append(a[i]+2*i)
  • The operation 2*x is invalid
  • plt is not an allowed object name
  • matplotlib cannot be used to plot functions
  • The list defined by x does not contain enough data
  • if val<m:
  • if val>m:
  • if val==m:
  • if val! =m:
  • z must be less than 0.0
  • z must be less than 1.0
  • z must be greater than 1.0
  • z must be greater than 100.0
  • xdict= {‘k1’: ‘v1’, ‘k2’: ‘v2’, ‘k3’: ‘v3’}
  • xdict= {[‘k1’: ‘v1’, ‘k2’: ‘v2’, ‘k3’: ‘v3’]}
  • xdict= {(‘k1’: ‘v1’, ‘k2’: ‘v2’, ‘k3’: ‘v3’)}
  • xdict= {(‘k1’: ‘v1’), (‘k2’: ‘v2’), (‘k3’: ‘v3’)}
  • Add two values
  • At least one repetition
  • Allow for no repetitions
  • Concatenate two strings
  • It should include a ‘finally’ block
  • Its ‘except’ block will never execute
  • It does not mention a specific exception type
  • It should use an ‘else’ block to handle file errors
  • except NameError:

print(‘NameError’)

  • except TypeError:

print(‘TypeError’)

  • except IndexError:

print(‘IndexError’)

  • except ValueError:

print(‘ValueError’)

  • They avoid using nesting loop control structures
  • They apply class instances to accomplish a given task
  • They arrange small units of code in the order of their execution
  • They do not allow return arguments to be output from functions
  • Modify the __init__ method to be

def init (self, length, width, height):

length=self. length

width=self. width

height=self. height

  • Modify the __init__ method to be

def __init__ (self, length, width, height):

self. length=length

self. width=width

self. height=height

  • Modify the __str__ method to be

def str(self):

return ‘Length:’+str (self. length) +’ ‘+’Width:’+str (self. width) +’ ‘+’Height:’+str (self. height)

  • Modify the __str__ method to be

def __str__ (self, length, width, heigh):

return ‘Length:’+str (self. length) +’ ‘+’Width:’+str (self. width) +’ ‘+’Height:’+str (self. height)

def demorgan2(V, A, B):

    left_side = V. difference (A. intersection(B))

    right_side = V. difference(A). union (V. difference(B))

    if left_side == right_side:

        return True

    else:

        return False

def dictchk(x):

    new_dict = {}

    for key in x:

        if ‘k’ in key:

            new_dict[key] = x[key]

    return new_dict

  • 0, because division takes place before addition or subtraction
  • 0.0, because division takes place before addition or subtraction
  • 12, because addition and subtraction take place before division when using integers
  • An error, because this is invalid Python syntax
  • The string ‘z12’
  • 12 times the value input into the variable z
  • z copies of ’12’ will be concatenated together and output
  • An error, because the print expression mixes a string with a numeric value
  • for d in key:
  • for v in key:
  • for key in v:
  • for key in d:
  • -3
  • 2
  • 7
  • 8
  • s=’abcda.’
  • s=’abcdea.’
  • s=’……abc ‘
  • s=’……abc.’
  • There no input arguments to the function fexamp
  • The print instruction should be print (fexamp ())
  • The function definition line should be def fexamp:
  • The function definition line should be def fexamp ()
  • Multiple errors can be handled within a single ‘except’ block
  • Each ‘try’ block must be associated with exactly one ‘except’ block
  • The ‘except’ block will not execute unless the type of error is specified
  • An ‘else’ block must be included for handling the case where no error occurs
  • A Boolean variable
  • A user input variable
  • A fixed-length variable
  • A programmer-initialized variable
  • s += line
  • s += float(line)
  • s = s + int(line)
  • a = line

s = s + a

  • float
  • int
  • list
  • str
  • Store the pattern to a file
  • Convert the pattern into machine code
  • Increase the efficiency of pattern matching
  • Enable pattern matching using other programming languages

Introduction to Python

Python is a high-level, interpreted programming language known for its simplicity and readability. It’s widely used in various fields like web development, data analysis, artificial intelligence, scientific computing, and more. Here’s a quick introduction to Python:

Key Features:

  1. Easy to Learn and Read: Python’s syntax is designed to be readable and straightforward, making it an excellent choice for beginners.
  2. Interpreted Language: Python code is executed line-by-line, which makes debugging easier and allows for quick development.
  3. Dynamic Typing: You don’t need to declare the type of a variable; Python infers it at runtime.
  4. Versatile: Python can be used for a variety of applications, including web development (using frameworks like Django or Flask), data analysis (using libraries like Pandas and NumPy), and automation.

Libraries and Frameworks:

  • NumPy and Pandas: For numerical operations and data manipulation.
  • Matplotlib and Seaborn: For data visualization.
  • Requests: For making HTTP requests.
  • Django and Flask: For web development.

Getting Started:

  1. Install Python: Download and install Python from python.org.
  2. IDE/Text Editor: Use an Integrated Development Environment (IDE) like PyCharm, or a text editor like VSCode.
  3. Write Code: Start coding in Python and explore libraries and frameworks based on your interests.

Overall, Python’s simplicity, versatility, and community support make it an excellent choice for both beginners and experienced developers alike. Whether you’re building a simple script or a complex application. Python offers the tools and resources you need to get the job done efficiently.

You may also like

Leave a Comment

Indian Success Stories Logo

Indian Success Stories is committed to inspiring the world’s visionary leaders who are driven to make a difference with their ground-breaking concepts, ventures, and viewpoints. Join together with us to match your business with a community that is unstoppable and working to improve everyone’s future.

Edtior's Picks

Latest Articles

Copyright © 2024 Indian Success Stories. All rights reserved.