wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Session 1LNMIIT

Total questions: 30

Worksheet time: 30mins

Name
Class
Date
1.

Please select the correct expression to reassign a global variable “x” to 20 inside a function fun(1)

x = 50

def fun1():

# your code to assign global x = 20

fun1()

print(x) # it should print 20

a)

global x = 20

b)

global var x

x = 20

c)

global.x= 20

d)

global x

x = 20

2.

In Python3, Whatever you enter as input, the input() function converts it into a string

a)

True

b)

False

3.

What is the output of the following print() function

print('%d %d %.2f' % (11, '22', 11.22))

a)

11 22 11.22

b)

TypeError

c)

11 '22' 11.22

d)

None of the above

4.

What is the output of the following print() function

print(sep = '--', 'Ben', 25, 'California')

a)

Syntax Error

b)

Ben-25-California

c)

Ben 25 California

d)

None of these

5.

What will be displayed as an output on the screen

x = float('NaN')

print('%f, %e, %F, %E' % (x, x, x, x))

a)

nan, nan, NAN, NAN

b)

nan, NaN, nan, NaN

c)

NaN, NaN, NaN, NaN,

d)

None of these

6.

Use the following file to predict the output of the code

test.txt Content:

aaa

bbb

ccc

ddd

eee

fff

ggg

Code:

f = open("test.txt", "r")

print(f.readline(3))

f.close()

a)

bbb

b)

Syntax Error

c)

aaa

d)

aa

7.

What is the output of the following code

print('Pnative ', end='//')

print(' is for ', end='//')

print(' Python Lovers', end='//')

a)

Pnative /

is for /

Python Lovers /

b)

Pnative //

is for //

Python Lovers //

c)

Pnative // is for // Python Lovers//

d)

Pnative / is for / Python Lovers/

8.

What is the output of print('%x, %X' % (15, 15))

a)

15 15

b)

F F

c)

f f

d)

f F

9.

What does the following code do?

myAge = int (myAge)

a)

Converts the var (variable) myAge to a string

b)

Converts the var (variable) myAge to a integer

c)

Converts the var (variable) myAge from a integer to a string

d)

None of the above

10.

What will be the output?

name = 'Dave'

greeting = "Good morning" + name

print (greeting)

a)

Good moning 'Dave'

b)

Good morning Dave

c)

Good morning name

d)

Good morning + Dave

11.

What is the output of the following code

x = 50

def fun1():

x = 25

print(x)

fun1()

print(x)

a)

NameError

b)

25

25

c)

25

50

d)

None of the above

12.

Select the right way to create a string literal Ault'Kelly

a)

str1 = ‘Ault\\’Kelly’

b)

str1 = ‘Ault\’Kelly’

c)

str1 = “””Ault’Kelly”””

d)

None of the above

13.

What does the following code print?

def chair():

pp = 99

return pp


chair()


print(pp)

a)

NameError

b)

99

c)

pp

d)

99 pp

14.

What does the following code print?

qq = 3


def bike():

qq = 7


bike()


print(qq)

a)

qq

b)

3

c)

7

d)

Syntax Error

15.

What does the following code print?

cc = 2


if False:

cc = 66


def helmet():

if True:

cc = 40


helmet()


print(cc)

a)

66

b)

2

c)

40

d)

None of the above

16.

What is the output of the following code

fn = lambda x : x * x

print ( fn (4))

a)

4

b)

8

c)

16

d)

Error

17.

What will be the output of the following code

for char in 'Hello' :

print (char, end = ",")

a)

Hello

b)

H,e,l,l,o

c)

o.l,l,e,h

d)

Error

18.

What will be the output of the following code

x = 0

while x<3:

x +=1

print (x, end =' ')

else:

print('else block)

a)

012else block

b)

12else block

c)

123else block

d)

Syntax Error

19.

What is the output of the following code

s1={1,2,3,4}

s2={4,5,6,7}

print(s1&s2)

a)

{1,2,3,4,5,6,7}

b)

{1,2,3,5,6,7}

c)

{4}

d)

{123}

20.

What is the output of the following code

>>> x = 100

>>> type (x)

a)

integer

b)

int

c)

<class 'int'>

d)

<class 'number'>

21.

What is the output of the following code

>>> x=100

>>> y=100

>>> id (x) == id(y)

a)

True

b)

False

c)

Error

d)

None of the above

22.

Which of the following will give a syntax error?

a)

>>> x, y, z = 10, 20, 30

b)

>>> x, y, z = 10 , 'Hello' , True

c)

>>> x = 10, y= 'Hello' , 'True'

d)

None of the above

23.

What is the output of the following code?

x = 10

y = 20

x , y = y, x

print( x, y )

a)

10 20

b)

20 10

c)

0 0

d)

Syntax Error

24.

Which of the following will result in true?

a)

'0x12' .isdigit()

b)

'12.0' .isdigit()

c)

'012' .isdigit()

d)

'1.2e01' .isdigit()

25.

What will be the output of the following code?

var1="Hello"

var2= "World"

var3= "HelloWorld"


print(var1+var2 == var3)

print(var1 + var2 is var3)

a)

True

False

b)

False

False

c)

False

True

d)

True

True

26.

What will be the output of the following code?

def fn(x) :

try:

print(5/x)

except:

print('Error occured')

fn(0)

a)

5

b)

0.0

c)

Error occured

d)

ZeroDivisionError: division by zero

27.

What will be the output of the following code?

def fn(x):

try:

print(5/x)

Except ZeroDivisionError:

print("except block")

else

print("else block")

finally:

print("finally block")

fn(0)

a)

Except block

b)

Syntax error

c)

ValueError

d)

None of the above

28.

What does the following code do?

f = open ('c:\myfile.txt')

c = f.read()

a)

Reading a line from myfile.txt

b)

Reading content from the myfile.txt until EOF

c)

open the file and point to the first line of myfile.txt

d)

none of the above

29.

What will be the output of the following code?

nums {"One": 1, "Two" : 2}

print(nums ["One"])

a)

1

b)

"One"

c)

Syntax error

d)

Runtime error

30.

Which of the following is an invalid list object?

a)

list("Hello")

b)

[10 , 1.234. 2+3j, 'Python']

c)

[(1,2) (3,4)]

d)

All are valid