NEW
Font size
WorksheetsPython Data types & Exceptions
Total questions: 14
Worksheet time: 47mins
What will be the output of the following Python code?
l1=[2,4,6]
l2=[-2,-4,-6]
for i in zip(l1, l2):
print(i)
2, -2
4, -4
6, -6
[(2, -2), (4, -4), (6, -6)]
(2, -2)
(4, -4)
(6, -6)
[-4, -16, -36]
What will be the output of the following Python code?
a=[1,2,3]
b=a.append(4)
print(a)
print(b)
[1,2,3,4]
[1,2,3,4]
[1, 2, 3, 4]
None
Syntax error
[1,2,3]
[1,2,3,4]
What is the output of the following code
aTuple = (100, 200, 300, 400, 500)
aTuple[1] = 800
print(aTuple)
TypeError
(100, 800, 200, 300, 400, 500)
(800, 100, 200, 300, 400, 500)
What is the output of the following tuple operation
aTuple = (100,)
print(aTuple * 2)
TypeError
(100, 100)
(200)
Choose the correct way to access value 20 from the following tuple
aTuple = ("Orange", [10, 20, 30], (5, 15, 25))
aTuple[1:2][1]
aTuple[1:2](1)
aTuple[1:2][1]
aTuple[1][1]
What is the output of the following code
aTuple = (100, 200, 300, 400, 500)
print(aTuple[-2])
print(aTuple[-4:-1])
IndexError: tuple index out of range
400
(200, 300, 400)
(200,300,400)
300,400,500
Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which command do we use?
d.size()
len(d)
size(d)
d.len()
Consider the following list of pan card numbers:
pancard_list=["AABGT6715H", "UFFAC4352T", "IFSBD9163K", "JOOEC1225H","RWXAFE187B"]
9 OEC1225H
2 AFE187B
9163K O
225H A
What is the output of the code given below?
message="welcome to Mysore"
word=message[-7:]
if(word=="mysore"):
print("got it")
else:
message=message[3:14]
print(message)
got it
lcome to Myso
lcome to Mys
come to Myso
come to Mys
Choose the most appropriate function call needed at line 4 to get the output as ‘Result: 4’.
def check_value(message,num):
msg=message[:num]
return len(msg)
#function call statement
print("Result:", result)
result=check_value(‘Infosys’,3)
result=check_value(4,'Infosys‘)
result=check_value('Infosys',len('Infosys'))
result=check_value('Infosys',4)
result=check_value('Infosys',5)
What is the output of the following python code?
balance=1000
amount="300Rs"
def take_card():
print("Take the card out of ATM")
try:
if balance>=int(amount):
print("Withdraw")
else:
print("Invalid amount")
except TypeError:
print("Type Error Occurred")
except ValueError:
print("Value Error Occurred")
except:
print("Some error Occurred")
finally:
take_card()
Value Error Occurred
Take the card out of ATM
Type Error Occurred
Take the card out of ATM
Some Error occured
Invalid amount
Go through the below code and predict the output:
num1=100
num2=0
try:
result=num1/num2
print(result)
except ZeroDivisionError:
print("Zero Division Error Occurred")
100
0
Zero Division Error Occurred
What will be the output of the code given below?
def division(a,b):
try:
return int(a)/b
except TypeError:
print("Type error")
except ValueError:
print("Value error")
finally:
print("Finally")
print("Done")
division('A',10)
Value error
Finally
Done
Type error
Finally
Done
Type error
Finally
Value error
Finally
What will be the output of the below code?def find_sum(a,b):
try:
print(a+c)
except NameError:
print("Function name error")
finally:
print("Sum finally")
try:
find_sum(12,13)
except NameError:
print("Invocation name error")
finally:
print("Invocation finally")
Function name error
Function name error
Sum finally
Function name error
Sum finally
Function name error
Sum finally
Invocation finally
Invocation name error
Invocation finally
Sum finally
Invocation name error
Invocation finally
Invocation name error
Invocation finally
