0% found this document useful (0 votes)
27 views1 page

Practice Paper - Objective - I)

Uploaded by

Xya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views1 page

Practice Paper - Objective - I)

Uploaded by

Xya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Practice Paper - Objective -I) Total points 39/40

Revision Tour and Exception Handling

The respondent's email ([email protected]) was recorded on submission of this


form.

24 of 25 points

Enter your name *

Atharva Chauhan

Which of the following statements is a python keyword? 0/1

Break

WHILE

Math

False

Correct answer

False

_____________ function joins a string or character after each member of the 1/1
string.

None of the above

<str>.join(<string iterable>)

<str>.replace(<word to be replaced>, <replaced word)

<str>.split(<string/char>)

_________ function replaces a word or part of the string with the another in 1/1
a given string

None of the above

<str>.join(<string iterable>)

<str>.replace(<word to be replaced>, <replaced word)

<str>.split(<string/char>)

Which of the following is/are invalid keyword(s) in Python? 1/1

False

none

non_local

return

Other:

Find the invalid identifier from the following 1/1

Name

pass

none

address

Identify the invalid identifier out of the options given below 1/1

IF

Turn.over

Qwer_12

Play123

Identify the valid arithmetic operator in Python from the following- 1/1

And

>

**

Consider the given expression : 1/1

5<10 and 12>7 or not 7>4

Which of the following will be the correct output, if the given expression is
evaluated?

True

Null

False

None

What will be the output ? 1/1

>>> x = 125

>>> y = 13

>>> x // = y

>>> x

125/13

10

9.62

Find the output of the given expression- 1/1

1+(3-4)*2**10//6

171

-170

-171

Which of the following statements is true about tuples in Python? 1/1

Tuples can contain duplicate elements.

Tuples can only contain elements of the same data type.

Tuples can be indexed but not sliced.

Tuples are mutable.

Given the following Tuple Tup (10, 20, 30, 50) 1/1

Which of the following statements will result in an error?

print (Tup [0])

Tup.insert (2,3)

print (Tup [1:2])

print(len (Tup))

Which of the following is the correct way to call a function? 1/1

my_func()

def my_func()

return my_func

call my_func()

A function is defined as below, the function call parameters can be: 1/1

def first(a,b=9):
print(a,” “, b)

Two tuples

Two numbers

One number

All of the above

What will be the output of the python code? 1/1

def testify(b,a):
return a-b

sum=testify(22,55)
print(sum+30)

63

-33

33

Which of the following statements should be given in the blank for 1/1
#Missing Statement, if the output produced is 110?

b=100
def test(a):
--------------------------- # missing statement
b=b+a
test(10)
print(b)

global b

global a

global a=100

global b=100

What will be the output of the following code? 1/1

num=100
def showval(X):
global num
num = 85
if(X%2==0):
num += X
else:
num -= X
print(num,end="#")
showval(33)
print(num)

52#52

100#52

85#33

52#100

Find the impossible option from the following 1/1

>>> import random

>>> L=[i for i in range(random.randint(3,5))]

[0, 1, 2, 3, 4]

[0, 1, 2, 3]

[0, 1, 2]

[0, 1, 2, 3, 4, 5]

What possible outputs(s) are expected to be displayed on screen at the 1/1


time of execution of the program from the following code?

import random

AR=[20,30,40,50,60,70]

Lower=random.randint(1,3)

Upper=randm.randint(2,4)

for k in range(Lower, Upper+1):

print(AR[K], end=’#’)

30#40#50#

50#60#70#

10#40#70#

40#50#70#

Write the output of the code given below: 1/1


def short_sub (lst, n):
for i in range (0,n):
if len (lst)>4:
lst [i]=(lst) [i]+lst[i]
else:
lst[i]=lst[i]
subject=['CS','HINDI','PHYSICS','Eco','MATHS']
short_sub(subject,5)
print(subject)

['CSCS', 'HINDIHINDI', 'PHYSICSPHYSICS', 'EcoEco', 'MATHSMATHS']

['CS', 'HINDIHINDI', 'PHYSICSPHYSICS', 'EcoEco', 'MATHSMATHS']

['CSCS', 'HINDIHINDI', 'PHYSICSPHYSICS', 'Eco', 'MATHSMATHS']

['CS', 'HINDIHINDI', 'PHYSICSPHYSICS', 'Eco', 'MATHSMATHS']

Which function returns the sum of all elements of a list? 1/1

sum ()

count ()

total ()

add ()

What is the output of “class”+1+2+3? 1/1

Class1 2 3

Class123

Error

Class 1

Method to convert a string into lower case is: 1/1

islower(str)

str.lower()

str.tolower()

lower(str)

What will be the output ? 1/1

number = 5

while number <= 5:

if number < 5:

number = number + 1

print(number)

The program will loop indefinitely

The value of number will be printed exactly 5 times

The value of number will be printed exactly 1 time

The while loop will never get executed

What are the values of var1 and var2 that are printed when the following 1/1
code executes?

output = ""

var1 = -2

var2 = 0

while var1 != 0:

var1 = var1 + 1

var2 = var2 - 1

print("var1: " + str(var1) + " var2 " + str(var2))

var1 = 0, var2 = -2

var1 = 0, var2 = -1

This is an infinite loop, so nothing will be printed

var1 = -2, var2 = 0

Untitled Section 2 of 2 points

Consider the following code and answer the questions that follow:

Book={1:'Thriller', 2:'Mystery', 3:'Crime', 4:'Children Stories'}

Library ={'5':'Madras Diaries','6':'Malgudi Days'}

Ramesh needs to change the title in the dictionary book from ‘Crime’ to 1/1
‘Crime Thriller’. He has written the following command:

Book[‘Crime’]=’Crime Thriller’

But he is not getting the answer. Help him choose the correct command:

Book[2]=(’Crime Thriller’)

Book[2]=’Crime Thriller’

Book[3]=’Crime Thriller’

Book[3] =(‘Crime Thriller’)

What will be the output of the following line of code: 1/1

print(list(Library))

(‘5’,’Madras Diaries’,’6’,’Malgudi Days’)

[’Madras Diaries’,’Malgudi Days’]

[‘5’,’Madras Diaries’,’6’,’Malgudi Days’]

[‘5’,’6’]

Exception Handling 13 of 13 points

In Python, the else block after a try block executes only if no exceptions are 1/1
raised.

False

True

One of the following statements will raise error. Identify the statement that 1/1
will raise the error.

None of above will raise error

a=b=c=35

x,y=20

a,b=6,7*9

In Python, you can have multiple except blocks to handle different types of 1/1
exceptions.

True

False

What does the following code snippet do? 1/1


try:
assert 5 > 10, "AssertionError"
except AssertionError as e:
print(e)
finally:
print("Finally block executed")

Raises no error and prints “Finally block executed”

Raises an AssertionError and prints “False”, followed by “Finally block executed”

Raises an AssertionError and prints “AssertionError”, followed by “Finally block


executed”

Raises an AssertionError and prints “5 > 10”, followed by “Finally block executed”

When raising an exception using the raise statement, what is the minimum 1/1
requirement?

Specifying the exception type

Including a traceback

Providing a custom error message

Nothing, it's optional

Which of the following steps is NOT part of the exception handling 1/1
process?

Searching for an exception handler after an exception is raised.

Raising an exception when an error occurs.

Automatically correcting all programming errors without any additional code.

Executing the exception handler's code to manage the error.

Read the following statements and arrange in correct order. 1/1


A. Exception is raised
B. Executes exception
C. Program searches for exception handler
D. Create exception object
E. An error encountered
Choose the correct answer from the options given below:

E→D→A→C→B

E→D→B→C→A

A→B→C→D→E

E→D→C→A→B

Which of the following is NOT a standard Python exception type? 1/1

KeyError

ValueError

IndexError

TypeMismatchError

Which statement is/are true about Exception handling? 1/1

i. There can be try block without catch block but vice versa is not possible.

ii. There is no limit on the number of catch, block corresponding to a try


block.

iii. The object must be created of a specific class of which the error has
occurred otherwise runtime error will occur.

iv. To execute a code with each and every run of program, the code is
written in finally block.

i and ii, iv

ii and iv Only

Only ii

Only iii

Which of the following is true about the else block in Python exception 1/1
handling?

The else block is executed if an exception occurs

The else block is executed if no exceptions occur in the try block

The else block is optional in exception handling

The else block is always executed after the except block

What does the following code snippet do? 1/1


try:
x = int("abc")
except ValueError:
print("Invalid literal for int()")
finally:
print("Finally block executed")

Raises a ValueError exception

Terminates the program

Attempts to convert a string to an integer and prints an error message if it fails

Prints “Finally block executed” regardless of the outcome

Correct answer

Attempts to convert a string to an integer and prints an error message if it fails

Prints “Finally block executed” regardless of the outcome

What is the purpose of the assert statement in Python? 1/1

c) To define a new exception

To handle exceptions

To check for conditions that should be true during program execution

b) To terminate the program

Which of the following is a valid reason to use custom exceptions in 1/1


Python?

To reduce code readability

To replace built-in exceptions

To handle unexpected errors

To confuse the programmer

This form was created inside of Tagore International School. Report Abuse

Forms

You might also like