NEW
Font size
WorksheetsSession 1LNMIIT
Total questions: 30
Worksheet time: 30mins
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
global x = 20
global var x
x = 20
global.x= 20
global x
x = 20
In Python3, Whatever you enter as input, the input() function converts it into a string
True
False
What is the output of the following print() function
print('%d %d %.2f' % (11, '22', 11.22))
11 22 11.22
TypeError
11 '22' 11.22
None of the above
What is the output of the following print() function
print(sep = '--', 'Ben', 25, 'California')
Syntax Error
Ben-25-California
Ben 25 California
None of these
What will be displayed as an output on the screen
x = float('NaN')
print('%f, %e, %F, %E' % (x, x, x, x))
nan, nan, NAN, NAN
nan, NaN, nan, NaN
NaN, NaN, NaN, NaN,
None of these
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()
bbb
Syntax Error
aaa
aa
What is the output of the following code
print('Pnative ', end='//')
print(' is for ', end='//')
print(' Python Lovers', end='//')
Pnative /
is for /
Python Lovers /
Pnative //
is for //
Python Lovers //
Pnative // is for // Python Lovers//
Pnative / is for / Python Lovers/
What is the output of print('%x, %X' % (15, 15))
15 15
F F
f f
f F
What does the following code do?
myAge = int (myAge)
Converts the var (variable) myAge to a string
Converts the var (variable) myAge to a integer
Converts the var (variable) myAge from a integer to a string
None of the above
What will be the output?
name = 'Dave'
greeting = "Good morning" + name
print (greeting)
Good moning 'Dave'
Good morning Dave
Good morning name
Good morning + Dave
What is the output of the following code
x = 50
def fun1():
x = 25
print(x)
fun1()
print(x)
NameError
25
25
25
50
None of the above
Select the right way to create a string literal Ault'Kelly
str1 = ‘Ault\\’Kelly’
str1 = ‘Ault\’Kelly’
str1 = “””Ault’Kelly”””
None of the above
What does the following code print?
def chair():
pp = 99
return pp
chair()
print(pp)
NameError
99
pp
99 pp
What does the following code print?
qq = 3
def bike():
qq = 7
bike()
print(qq)
3
7
Syntax Error
What does the following code print?
cc = 2
if False:
cc = 66
def helmet():
if True:
cc = 40
helmet()
print(cc)
66
2
40
None of the above
What is the output of the following code
fn = lambda x : x * x
print ( fn (4))
4
8
16
Error
What will be the output of the following code
for char in 'Hello' :
print (char, end = ",")
Hello
H,e,l,l,o
o.l,l,e,h
Error
What will be the output of the following code
x = 0
while x<3:
x +=1
print (x, end =' ')
else:
print('else block)
012else block
12else block
123else block
Syntax Error
What is the output of the following code
s1={1,2,3,4}
s2={4,5,6,7}
print(s1&s2)
{1,2,3,4,5,6,7}
{1,2,3,5,6,7}
{4}
{123}
What is the output of the following code
>>> x = 100
>>> type (x)
integer
int
<class 'int'>
<class 'number'>
What is the output of the following code
>>> x=100
>>> y=100
>>> id (x) == id(y)
True
False
Error
None of the above
Which of the following will give a syntax error?
>>> x, y, z = 10, 20, 30
>>> x, y, z = 10 , 'Hello' , True
>>> x = 10, y= 'Hello' , 'True'
None of the above
What is the output of the following code?
x = 10
y = 20
x , y = y, x
print( x, y )
10 20
20 10
0 0
Syntax Error
Which of the following will result in true?
'0x12' .isdigit()
'12.0' .isdigit()
'012' .isdigit()
'1.2e01' .isdigit()
What will be the output of the following code?
var1="Hello"
var2= "World"
var3= "HelloWorld"
print(var1+var2 == var3)
print(var1 + var2 is var3)
True
False
False
False
False
True
True
True
What will be the output of the following code?
def fn(x) :
try:
print(5/x)
except:
print('Error occured')
fn(0)
5
0.0
Error occured
ZeroDivisionError: division by zero
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)
Except block
Syntax error
ValueError
None of the above
What does the following code do?
f = open ('c:\myfile.txt')
c = f.read()
Reading a line from myfile.txt
Reading content from the myfile.txt until EOF
open the file and point to the first line of myfile.txt
none of the above
What will be the output of the following code?
nums {"One": 1, "Two" : 2}
print(nums ["One"])
1
"One"
Syntax error
Runtime error
Which of the following is an invalid list object?
list("Hello")
[10 , 1.234. 2+3j, 'Python']
[(1,2) (3,4)]
All are valid
