0% found this document useful (0 votes)
84 views

What will be the output of the following Python code

Uploaded by

avnikumar32
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

What will be the output of the following Python code

Uploaded by

avnikumar32
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Q1.

Consider the following python code:


age=0 minor=False name='Saachi'
[The types of age,minor and name variables respectively: ]
#A) int, bool, str
B) bool, bool, str
C) int, bool, char
D) float, bool, str

Q2. Consider the following python code:


weight=62.4
zip='80098'
value=+23E4
[The types of weight,zip and value variables respectively: ]
A)float, str, str
B)int, str, float
C)double, str, float
#D)float, str, float

Q3. You are writing a Python program to read two int values from the
keyboard and print the sum.
x=input('Enter First Number:')
y=input('Enter Second Number:')
#Line-1 Which of the following code we have to write at Line-1 to print
sum of given numbers? ]
#A) print('The Result:'+(int(x)+int(y)))
B) print('The Result:'+(int(x+y)))
C) print('The Result:'+str(int(x)+int(y))) *
D) print('The Result:'+str(int(x+y)))

Q4. Consider the code:


#Do not understand
start=input('How old were you at the time of joining?')
end=input('How old are you today?')
Which of the following code is valid to print Congratulations message? ]
A) print('Congratulations on '+ (int(end)-int(start))+' Years of
Service!')
B) print('Congratulations on '+ str(int(end)-int(start))+' Years of
Service!')
C) print('Congratulations on '+ int(end-start)+' Years of Service!')
D) print('Congratulations on '+ str(end-start)+' Years of Service!')

Q5. You are writing a Python program. You required to handle data types
properly. Consider the code segment:
a=10+20
b='10'+'20'
c='10'*3
Identify the types of a,b and c? ]
#A) a is of int type,b is of str type and c is of str type
B) a is of int type,b is of str type and c is of int type
C) a is of int type,b is of int type and c is of int type
D) a is of int type ,b and c are invalid declarations

Q6. What is the output of the following python code?


Old_list =[1,2,3]
New_list =[i for i in [Old_list]]
for i in range(4):
print(New_list)
Q7. What is the output of the following statement?
print(3*0.1==0.3)
#true
false

Q7. You are developing a python application for your company.


A list named employees contains 500 employee names,the last 3 being
company management. Which of the following represents only management
employees. ]
A) employees[497:]
B) employees[-3:]
C) employees[497:500]
#D) All the above

Q8. You are developing a python application for your company. A list
named employees contains 500 employee names.
In which cases we will get IndexError while accessing employee data? ]
A) employees[1:1000]
B) employees[-10:10]
C) employees[0:501]
#D) None of the above

Q9. You are developing a python application for your company.


A list named employees contains 500 employee names. In which cases we
will get IndexError while accessing employee names?
A) employees[0]
#B) employees[500]
C) employees[-1]
D) None of the above

Q10. Consider the list:


list=['Apple','Banana','Carrot','Mango'] Which of the following are valid
ways of accessing 'Mango': ]
A) list[0]
B) list[-1]
C) list[4]
#D) list[3]

Q11. Consider the following lists:


n1=[10,20,30,40,50]
n2=[10,20,30,40,50]
print(n1 is n2)
print(n1 == n2)
What is the output? ]
A) TrueTrue
B) FalseFalse
#C) FalseTrue
D) TrueFalse

Q11A. Consider the following lists:


n1=[10,20,30,40,50]
n2=[10,20,30,40,50]
print(n1[0] is n2[0])
print(n1[0] == n2[0])
What is the output? ]
#A) TrueTrue
B) FalseFalse
C) FalseTrue
D) TrueFalse

Q11B. Consider the following tuples:


n1=(10,20,30,40,50)
n2=(10,20,30,40,50)
print(n1 is n2)
print(n1 == n2)
What is the output?
#A) True True
B) False False
C) False True
D) True False

Q12. Consider the following lists:

n1=[10,20,30,40,50]
n2=[10,20,30,40,50]
print(n1 is n2)
print(n1 == n2)
n1=n2
print(n1 is n2)
print(n1 == n2)
What is the result?
A) FalseFalseTrueTrue
B) FalseTrueFalseTrue
C) TrueFalseTrueFalse
#D) FalseTrueTrueTrue*

Q13. Consider the lists:

numbers=[10,20,30,40,50]
alphabets=['a','b','c','d','e']
print( numbers is alphabets)
print( numbers == alphabets)
numbers=alphabets
print( numbers is alphabets)
print( numbers == alphabets)

What is the result? ]


#A) FalseFalseTrueTrue
B) FalseTrueFalseTrue
C) TrueFalseTrueFalse
D) FalseTrueTrueTrue

Q14. Consider the code

a=15
b=5
print(a/b)
What is the result ?
A) 3
#B) 3.0
C) 0
D) 0.0

Q15. Consider the code

a=21
b=6
print(a/b)
print(a//b)
print(a%b)
What is the result?
A)3,3,3
#B)3.5,3,3
C)3.0,3,3
D)3.5,3.5,3

Q16. Consider the following expression


result=(2*(3+4)**2-(3**3)*3)
What is result value? ]
#A)17
B)16
C)18
D)19

Q17. Consider the expession:


result=a-b*c+d
Which of the following are valid? ]
A) First b*c will be evaluated followed by subtraction and addition
#B) First b*c will be evaluated followed by addition and subtraction
C) First a-b will be evaluated followed by multiplication and addition
D) The above expession is equivalent to a-(b*c)+d

Q18. Consider the following code segments

#Code Segment-1 a1='10' b1=3 c1=a1*b1 #Code Segment-2 a2=10 b2=3


c2=a2/b2 #Code Segment-3 a3=2.6 b3=1 c3=a3/b3 After executing Code
Segments 1,2 and 3 the result types of c1,c2 and c3 are: ]
- A. c1 is of str type,c2 is of int type ,c3 is of float type
- B. c1 is of str type,c2 is of float type ,c3 is of float type
- C. c1 is of str type,c2 is of int type ,c3 is of int type
- D. c1 is of str type,c2 is of str type ,c3 is of str type

Q19. Which of the following is valid python operator precedence order? ]


- A)ParenthesisExponentUnary Positive,Negative n NotAddition n
SubtractionMultiplication n DivisionAnd
- B) ExponentsParenthesisUnary Positive,Negative n NotMultiplication n
DivisionAddition n Subtraction
- C) ExponentsUnary Positive,Negative n NotMultiplication n
DivisionAddition n Subtraction,Parenthesis
- D) ParenthesisExponentsUnary Positive,Negative n NotMultiplication n
DivisionAddition n Subtraction

Q20. You have the following code:

a=bool([False]) b=bool(3) c=bool("") d=bool(' ') Which of the variables


will represent False: ]
- A) a
- B) b
- C) c
- D) d

Q21. Consider the following variable declarations:


a= bool([]) b= bool(()) c= bool(range(0)) d= bool({}) e= bool(set())
Which of the above variables represent True ? ]
- A) c
- B) a ,b, c, d
- C) All Variables represent True
- D) None of the variables represents True

Q22.
a=bool(0)
b=bool(3) c=bool(0.5) d=bool(0.0) Which variables represent True? ]
- A) a,b
- B) b,c
- D) d,a
- E) All Variables

Q23. You have the following code:


a=3
b=5
a += 2**3
a -=b//2//3
print(a)
What is the result? ]
- A)13
- B)12
- C)11
- D)10

Q24. Consider the following expression


result=8//6%5+2**3-2 print(result) What is the result? ]
- A) 6
- B) 7
- C) 8
- D) 9

Q25. Which of the following expression will generate max value? ]


- A)8%3*4
- B)8-3*4
- C)8//3*4
- D)8/3*4

Q26. Consider the code

a=2 a += 1 # Line-1 To make a value as 9,which expression required to


place at Line-1 ]
- A) a*=2
- B) a**=2
- C) a+=2
- D) a-=2

Q27. Consider the python code


a=1
b=3
c=5
d=7 In Which of the following cases the result value is 0? ]
- A) result = a+b*2
- B) result = a%b-1
- C) result = a-b//d
- D) result = a**d-1
Q28. In which of the following cases we will get same result ]
- A) 23%5
- B) 3**1
- C) 11/3
- D) 13//4

Q29. Consider the code


a=1
b=2
c=4
d=6
Which of the following expression results -4? ]
- A) (a+b)//c%d
- B) (b+c)//a%d
- C) (a+b)//c*d
- D) (a+b)//d-c

Q30.
subjects=['java','python','sap']
more_subjects=['java','python','sap']
extra_subjects=more_subjects
In which cases True will be printed to the console? ]
- A) print(extra_subjects is more_subjects)
- B) print(subjects is more_subjects)
- C) print(subjects is extra_subjects)
- D) print(subjects == extra_subjects)

Q31. Consider the python code


numbers=[10,20,30,40] x=0
In which of the following cases 10 will be printed to the console? ]
- A)for i in (30,40,50): if i in numbers: x=x+5print(x)
- B)for i in (30,40,50): if i not in numbers: x=x+5print(x)
- C)for i in (30,40,50): if i not in numbers: x=x+10
- D)for i in (30,40,50): if i in numbers: x=x+10

Q32. Which of the following code snippet will produce the output:
Boy Cat Dog ]
- A)l=['Apple','Boy','Cat','Dog']for x in l: if len(x) == 3: print(x)
- B)l=['Apple','Boy','Cat','Dog']for x in l: if len(x) != 3: print(x)
- C)l=['Apple','Boy','Cat','Dog']for x in l: print(x)
- D)l=['Apple','Boy','Cat','Dog']l1=l[1:]for x in l1: print(x)

Q33. Consider the Python code:


a=5
b=10
c=2
d=True
x=a+b*c
y=a+b/d
if(condition):
print('Valid')
else:
print('invalid')
To print 'Valid' to the console, which condition we have to take for if
statement? ]
- A) x<y
- B) x<=y
- C) x>y
- D) x==y

Q34. Consider the following code


x= 'Saachi'
y= 'Saachi'
result=condition
print(result)
For which of the following condition True will be printed to the console?
]
- A) x is y
- B) x is not y
- C) x != y
- D) x < y

Q35. Consider the code:


x= 8
y= 10 result= x//3*3/2+y%2**2 print(result) What is the result? ]
- A) 5
- B) 5.0
- C) 6.0
- D) 7.0

Q36. Consider the code


s='AB CD'
list=list(s) list.append('EF') print(list) What is the result? ]
- A)('A','B',' ','C','D','EF')
- B)['A','B','C','D','EF']
- C)['A','B','C','D','E','F']
- D)['A','B',' ','C','D','EF']
- E){'A','B',' ','C','D','EF'}

Q37. Consider the code:


x='ACROTE'
y='APPLE' z='TOMATO' Which of the following won't print 'CAT' to the
console ]
- A) print(x[1]+y[0]+z[0])
- B) print(x[2]+y[1]+z[1])
- C) print(x[-5]+y[0]+z[0])
- D) print(x[-5]+y[0]+z[-2])

Q38. Consider the code:


s='Python is easy'
s1=s[-7:] s2=s[-4:] print(s1+s2) What is the result? ]
- A)is easyeasy
- B)easyeasy
- C)iseasyeasy
- D)s easyeasy
- E)is easy easy

Q39. Consider the code


t=([10,20],10,False)
Which line of the code assigns <class 'list'> to x ]
- A) x= type(t)
- B) x= type(t[0])
- C) x= type(t[1])
- D) x= type(t[0:])
Q40. Consider the variable declaration
b = 'BANANA'
Which of the following lines will print 'AA' to the console? ]
- A) print(b[1]+b[2])
- B) print(b[1]+b[3])
- C) print(b[1]+b[5])
- D) print(b[3]+b[5])

Q41. Consider the Variable declarations:

a='5' b='2' Which of the following expressions are of type str ]


- A) a+b
- B) a*b
- C) a-b
- D) a*2

Q42. Which expression would evaluate to 2? ]


- A) 3**2
- B) 22%5
- C) 13//4
- D) 11/2

Q43. Consider the code


a=7
b=3 c=5 d=1 Which line of the code assigns 9 to the output? ]
- A) output=a%c+1
- B) output=a+c//d
- C) output=c*d-1
- D) output=a+d*2

Q44. Consider the code


x=3 x +=1 #Line-1 Which line should be inserted at Line-1 so that x
value will become 16? ]
- A)x+=2
- B)x-=2
- C)x*=2
- D)x**=2

Q45. In which of the following cases, True will be printed to the console
? ]
- A)a=45b=45print(a is not b)
- B)s1='The Python Course's2='The Python Course'.upper()print(s1 is s2)
- C)x=[1,2,3]y=[1,2,3]print(x is y)
- D)print('r' in 'durga')
- E)print('is' in 'This IS a Fake News')

Q46) Which expression evaluates to 4? ]


- A) 7/2*3
- B) 7%2+3
- C) 7//2-3
- D)7-2*3

Q47) Consider the following expression:

6//4%5+2**3-2//3 This expression results to:


- A)9
- B)3
- C)-1
- D)25

Q48)Consider the code


x=2
y=6 x+=2**3 x//=y//2//3 print(x) What is the output? ]
- A)0
- B)9
- C)10
- D)7

Q49) Consider the Code

x=3/3+3**3-3 print(x) What is the output? ]


- A)25
- B)32
- C)0.11
- D)25.0

Q50) Consider the code


count=input('Enter the number of customers of the bank:')
#Line-1 print(output) Which code inserted at Line-1 will print 20 to the
console if we pass 15 as count value from the console?
- A)output=int(count)+5
- B)output=count+5
- C)output=str(count)+5
- D)output=float(count)+5

Q53. In which of the following cases we will get <class 'int'> as output?
]
- A)x=47.0print(type(x))
- B)x='47'print(type(x))
- C)x=10+20jprint(type(x))
- D)x=2**2**2print(type(x))

Q54. Which of the following are valid statements? ]


- A) 5+False evaluates to False
- B) True+1 evaluates to 2
- C) True and False evaluates to False
- D) True or False evaluates to False
- E) type('') is <class 'bool'>

Q55. Which of the following string declarations spans more than one line
and considers whitespace properly when the string is printed to the
console? ]
- A) s1='durga software solutions'
- B) s1="durga software solutions"
- C) s1='durga\n software\n solutions'
- D) s1='''durga software solutions'''

Q56)
Consider the following code:
print(type(input('Enter some value:'))) if we enter 10 and 10.0
individually for every run what is the output? ]
- A)<class 'str'><class 'str'>
- B)<class 'int'><class 'float'>
- C)<class 'int'><class 'int'>
- D)<class 'float'><class 'float'>
Q57)
Consider the following code:
print(type(eval(input('Enter some value:')))) if we enter 10 and 10.0
individually for every run what is the output? ]
- A)<class 'str'><class 'str'>
- B)<class 'int'><class 'float'>
- C)<class 'int'><class 'int'>
- D)<class 'float'><class 'float'>

Q59) Consider the code


x='10'
y='20' The type of x+y ? ]
- A)int
- B)float
- C)str
- D)complex

Q60) Consider the code


a=float('123.456')
Which expression evaluates to 2? ]
- A)int(a)+False
- B)bool(a)+True
- C)str(a)
- D)bool(a)

Q61)
x='TEXT'
which line of the code will assign 'TT' to the output? ]
- A) output=x[0]+x[2]
- B) output=x[1]+x[1]
- C) output=x[0]+x[-1]
- D) output=x[1]+x[4]

Q62. Consider the Python code:

l1=['sunny','bunny','chinny','vinny']
l2=['sunny','bunny','chinny','vinny'] print(l1 is not l2) print(l1 != l2)
l1=l2 print(l1 is not l2) print(l1 != l2) What is the result? ]
- A)TrueTrueFalseFalse
- B)TrueFalseTrueFalse
- C)TrueFalseFalseTrue
- D)TrueFalseFalseFalse

Q63. Consider the Python Code

l1=['sunny','bunny','chinny','vinny']
l2=['sunny','bunny','chinny','vinny'] print(l1 is l2) print(l1 == l2)
l1=l2 print(l1 is l2) print(l1 == l2) What is the result? ]
- A)FalseTrueTrueTrue
- B)FalseFalseTrueTrue
- C)FalseTrueFalseTrue
- D)FalseTrueTrueFalse

Q64. Consider the python code:

print(10==10 and 20!=20) print(10==10 or 20!=20) print( not 10==10)


What is the result? ]
- A)TrueTrueFalse
- B)FalseTrueTrue
- C)FalseTrueFalse
- D)FalseFalseFalse

Q65. Consider the code:

print(not 0) print(not 10) print(not '') print(not 'durga') print(not


None) What is the result? ]
- A)TrueFalseFalseFalseTrue
- B)TrueFalseTrueFalseTrue
- C)FalseFalseTrueFalseTrue
- D)TrueFalseTrueFalseFalse

Q66. Consider the code:

lst = [7, 8, 9] b = lst[:] print(b is lst) print(b == lst) What is the


result? ]
- A)FalseTrue
- B)FalseFalse
- C)TrueFalse
- D)TrueTrue

Q67. Consider the following code:

v1 = 1 v2 = 0 v1 = v1 ^ v2 v2 = v1 ^ v2 v1 = v1 ^ v2 print(v1) What is
the result? ]
- A) 0
- B) 1
- C) 2
- D) 3

Q68. Consider the Python code:

a=['a','b','c','d']
for i in a:
a.append(i.upper())
print(a)
What is the result? ]
- A) ['a','b','c','d']
- B) ['A','B','C','D']
- C) SyntaxError
- D) MemoryError thrown at runtime

Q69. Consider the python code:

result=str(bool(1) + float(10)/float(2))
print(result)
What is the output? ]
- A) SyntaxError
- B) TypeError
- C) 6
- D) 6.0

Q70. Consider the code

s='DURGA SOFT'
Which of the following lines will assign 9 to variable result? ]
- A) result = len(s)
- B) result = len(s.lstrip())
- C) result = len(s.rstrip())
- D) result = len(s.strip())
- E) result = len(s.replace(' ',''))

Q71. We are developing a python program, where user has to enter number
of items, which should be int type.Even user enter decimal value, it
should be treated as int type only. Which of the fllowing code segment
meets our requirement? ]
- A. n = input("Enter The Number Of Items?")
- B. n = float(input("Enter The Number Of Items?"))
- C. n = str(input("Enter The Number Of Items?"))
- D. n = int(float(input("Enter The Number Of Items?")))

You develop a Python application for your company. You required to accept
input from the user and print that information to the user screen.

Consider the code:


print('Enter Your Name:') #Line-1 print(name)
At Line-1 which code we have to write? ]
- A) name=input
- B) input('name')
- C) input(name)
- D) name=input()

Q72. If the user enters 12345 as input,Which of the following code will
print 12346 to the console? ]
- A)count=input('Enter count value:')print(count+1)
- B)count=input('Enter count value:')print(int(count)+1)
- C)count=eval(input('Enter count value:'))print(count+1)
- D)count=int(input('Enter count value:'))print(count+1)

From sys module, by using which variable we can access command line
arguments? ]
- A) argv
- B) args
- C) argsv
- D) arguments

Q73. Given the command invocation:

py test.py Durga Which of the following code prints 'Durga' to the


console? ]
- A)from sys import args print(args[0])
- B)from sys import args print(args[1])
- C)from sys import argv print(argv[0])
- D)from sys import argv print(argv[1])

Q74. Consider the code:


from sys import argv
print(argv[0]) and given the command invocation: py test.py DURGASOFT
What is the result? ]
- A) DURGASOFT
- B) test.py
- C) IndexError will be thrown at runtime
- D) ImportError will be thrown at runtime

Q75. Consider the code:


from sys import argv
print(argv[1]+argv[2]) and given the command invocation: py test.py 10
20 What is the result? ]
- A) 30
- B) 1020
- C) IndexError will be thrown at runtime
- D) ImportError will be thrown at runtime

Q76.
Consider the following code:
numbers=[0,1,2,3,4,5,6,7,8,9]
index=0
while (index<10) #Line-1
print(numbers[index])
if numbers(index) = 6 #Line-2
break
else:
index += 1
To print 0 to 6,which changes we have to perform in the above code? ]
- A) Line-1 should be replaced with while(index<10):
- B) Line-2 should be replaced with if numbers[index]==6:
- C) Line-2 should be replaced with if numbers[index]=6:
- D) Line-1 should be replaced with while(index>0):

Q77. Consider the following code

def my_list(x):
lst.append(a)
return lst

my_list('chicken')
my_list('mutton')
print(my_list('fish'))
to print the following to the console ['chicken','mutton','fish'] x
should be replaced with ]
- A)a,lst=[]
- B)a,lst=()
- C)a,lst={}
- D)a,lst=None

Q78. Consider the following code:

def f1(x=0,y=0):
return x+y
Which of the following method calls are valid? ]
- A) f1()
- B) f1('10','20')
- C) f1(10)
- D) f1('10')

Q79. Consider the following code:

def f1(x=0,y=0):
return x*y
Which of the following method calls are valid? ]
- A) f1()
- B) f1('10','20')
- C) f1(10)
- D) f1('10')

Q80. Consider the code:

def calculate(amount=6,factor=3):
if amount>6:
return amount*factor
else:
return amount*factor*2
Which of the following function calls returns 30 ]
- A) calculate()
- B) calculate(10)
- C) calculate(5,2)
- D) calculate(1)

Q81. Consider the following code


def fib_seq(n):
if n==0:
return 0
elif n==1:
return 1
else:
return fib_seq(n-1)+fib_seq(n-2)

for i in range(7):
print(fib_seq(i),end=',')
What is the result? ]
- A) 0,1,1,2,3,5,8,
- B) 0,1,2,4,8,16,32
- C) 0,1,0,2,0,4,0,
- D) None of these

Q82. Which of the following is False? ]


- A) A try statement can have one or more except clauses
- B) A try statement can have a finally clause without an except clause
- C) A try statement can have a finally clause and an except clause
- D) A try statement can have one or more finally clauses

Q83. Consider the code

a=10 b=20 c='30' result=a+b+c What is the result? ]


- A) 102030
- B) 3030
- C) TypeError
- D) ArithmeticError

Q84. Consider the code

def area(b,w): return B*w print(area(10,20)) What is the result? ]


- A) NameError will be raised at runtime
- B) AttributeError will be raised at runtime
- C) IdentationError will be raised at runtime
- D) 200

q85.Consider the code:

import math l =[str(round(math.pi)) for i in range (1, 6)] print(l)


What is the result? ]
- A) ['3', '3', '3', '3', '3']
- B) ['3', '3', '3', '3', '3','3']
- C) ['1', '2', '3', '4', '5']
- D) ['1', '2', '3', '4', '5','6']

Q86.You are writing code that generates a random integer with a minimum
value of 5 and maximum value of 11. Which of the following 2 functions we
required to use? ]
- A. random.randint(5,12)
- B. random.randint(5,11)
- C. random.randrange(5,12,1)
- D. random.randrange(5,11,1)

Q87 Consider the following code:

import random fruits=['Apple','Mango','Orange','Lemon']


Which of the following will print some random value from the list? ]
- A) print(random.sample(fruits))
- B) print(random.sample(fruits,3)[0])
- C) print(random.choice(fruits))
- D) print(random.choice(fruits)[0])

Q88. We are developing an application for the client requirement.As the


part of that we have to create a list of 7 random integers between 1 and
7 inclusive.

Which of the following code should be used? ]


- A) import randomrandints=[random.randint(1,7) for i in range(1,8)]
- B) import randomrandints=[random.randint(1,8) for i in range(1,8)]
- C)import randomrandints=random.randrange(1,7)
- D)import randomrandints=random.randint(1,7)

Q89. Consider the code:


import random fruits=['Apple','Mango','Orange','Lemon']
random_list=[random.choice(fruits)[:2] for i in range(3)]
print(''.join(random_list)) Which of the following are possible outputs?
]
- A) ApApAp
- B) ApMaOr
- C) LeMaOr
- D) OrOraM

Q90. Consider the python code:

import random print(int(random.random()*5)) Which of the following is


true? ]
- A) It will print a random int value from 0 to 5
- B) It will print a random int value from 1 to 5
- C) It will print a random int value from 0 to 5
- D) It will print a random int value from 0 to 4
- E) It will print 5

Q91. Consider the code

import random print(random.sample(range(10), 7)) Which of the following


is valid? ]
- A) It will print list of 10 unique random numbers from 0 to 6
- B) It will print list of 7 unique random numbers from 0 to 9
- C) It will print list of 7 unique random numbers from 0 to 10
- D) It will print list of 7 unique random numbers from 1 to 10

Q92 You want to add comments to your code so that other team members can
understand it.
What should you do? ]
- A. Place the comments after the #sign on any line
- B. Place the comments after the last line of the code separated by a
blank line
- C. Place the comments before the first line of code separated by a
blank line
- D. Place the comments inside parentheses anywhere

Q93 Consider the following python code:

x = 'durga' print(x) y=x x+='soft' print(x) print(y) What is the output:


]
- A)durga,durga,softdurga
- B)durga,durga,softdurgasoft
- C)durga,durga,durga
- D) None of these

Q94 Consider the following code:

print( 0 or 50)
print( 0 and 50)
What is the result? ]
- A) True,False
- B)False,True
- C)0,50
- D)50,0

Q95. Consider the following code:

print(bool(0))
print(bool(50))
What is the result? ]
- A)False,True
- B)True,True
- C)False,False
- D)True,False

Q96. Consider the following code:

print(None is None) print(None == None) What is the result? ]


- A)FalseTrue
- B)TrueTrue
- C)FalseFalse
- D)TrueFalse

Q97. Consider the following code:


print(-10<0<10)
print(-10<0>10) What is the result? ]
- A)FalseTrue
- B)TrueTrue
- C)FalseFalse
- D)TrueFalse
Q98. Consider the following code:

l1 = [10,20]
l2= [30,40]
l3= l1+l2
l4=l3*2
print(l4)
What is the result? ]
- A) [10, 20, 30, 40, 10, 20, 30, 40]
- B) [20, 40, 60, 80]
- C) [10, 20, 30, 40]
- D) None of these

Q99. Consider the following code:

import math x = True


y = 0
while (x):
if y == 0:
result = math.pi/y
y += 5
else:
result=0
y=0
Which of the following is valid? ]
- A) We will get SyntaxError because y += 5 is invalid
- B) The loop will be executed infinite times without printing anything.
- C) We will get ZeroDivisionError.
- D) None of these

Q100. Which of the following will print string left-aligned in a column


of 10 spaces. ]
- A. print('Name:{0:20}.'.format('durga'))
- B. print('Name:{20:0}.'.format('durga'))
- C. print('Name:{:20}.'.format('durga'))
- D. print('Name:{0:>20}.'.format('durga'))

Q101. The Value must print right alined in a column of 10 spaces wide
with upto one digit after decimal point. Which of the following code will
meet this requirement. ]
- A. print('Value:{:10.1f}.'.format(1.45678))
- B. print('Value:{:<10.1f}.'.format(1.45678))
- C. print('Value:{10:.1f}.'.format(1.45678))
- D. print('Value:{10:.1f}.'.format(1.45678))

Q102 Consider the code

def area(b,w): return B*w print(area(10,20)) What is the result? ]


- A) NameError will be raised at runtime
- B) AttributeError will be raised at runtime
- C) IdentationError will be raised at runtime
- D) 200

====================IGNORE THIS PART==============================


Q2. Which type of exception will be raised if we are trying to call a
method on the inappropriate object? ]
- A) IndexError
- B) TypeError
- C) AttributeError
- D) None of these

Q3. Consider the code

f=open('abc.txt') f.readall() Which exception will be raised? ]


- A) AttributeError
- B) EOFError
- C) SystemError
- D) SyntaxError

Q4. Consider the code


def f1():
try: return 1 finally: return 2 x=f1() print(x) What is the
result? ]
- A) 1
- B) 2
- C) prints both 1 and 2
- D) Error, because more than one return statement is not allowed

Q5. Which of the following are True? ]


- A) A try block can have any number of except blocks
- B) A try block should be associated with atmost one finally block
- C) A try block should be associated with atmost one else block
- D) All the above

Q6. The base class for all exceptions in python is: ]


- A) ExceptionBase
- B) BaseException
- C) Exception
- D) EOFError

Q7. Which of the following is True about else block? ]


- A) else block will be executed if there is no exception in try block
- B) Without writing except block we cannot write else block
- C) For the same try we can write atmost one else block
- D) All the above

Q8. Consider the code:

try: print('try') except: print('except') else: print('else') finally:


print('finally') What is the result? ]
- A)try,except,else,finally
- B)try,else,finally
- C)try,except,finally
- D)try,finally

Q9.
Consider the code
try: print('try') print(10/0) except: print('except') else:
print('else') finally: print('finally') What is the result? ]
- A)trye,xceptelse,finally
- B)try,else,finally
- C)try,except,finally
- D)try,finally

Q10. Consider the code :

try: print('try') print(10/0) else: print('else') except:


print('except') finally: print('finally') ]
- A)try,else,except,finally
- B)try,else,finally
- C)try,except,finally
- D) SyntaxError: invalid syntax

Q19. Consider the code:

a=10 b=0 try: print(a/b) Which of the following except block print the
name of exception which is raised,i.e exception class name? ]
- A)except ZeroDivisionError as e: print('Exception
Type:',e.__class__.__name__)
- B)except ZeroDivisionError as e: print('Exception
Type:',type(e).__name__)
- C)except ZeroDivisionError as e: print('Exception Type:',e)
- D) All of these

Q20. Which of the following is valid way of creating our own custom
exception? ]
- A)class MyException: pass
- B) class MyException(): pass
- C)class MyException(Exception): pass
- D) It is not possible to define custom exceptions in python

Q21. Consider the code

x=int(input('Enter First Number:')) y=int(input('Enter Second Number:'))


try: print(x/y) Which of the following is valid except block that
handles both ZeroDivisionError and ValueError ]
- A) except(ZeroDivisionError,ValueError) from e: print(e)
- B)except(ZeroDivisionError,ValueError) as e: print(e)
- C)except(ZeroDivisionError | ValueError) as e: print(e)
- D)except(ZeroDivisionError, ValueError as e): print(e)

Q1. Consider the following code.

import os def get_data(filename,mode): if os.path.isfile(filename):


with open(filename,'r') as file: return file.readline() else:
return None Which of the following are valid about this code? ]
- A) This function returns the first line of the file if it is available
- B) This function returns None if the file does not exist
- C) This function returns total data present in the file
- D) This function returns last line of the file

Q3. You develop a python application for your school.


You need to read and write data to a text file. If the file does not
exist,it must be created. If the file has the content,the content must be
removed.
Which code we have to use? ]
- A) open('abc.txt','r')
- B) open('abc.txt','r+')
- C) open('abc.txt','w+')
- D) open('abc.txt','w')

Q8. To write 'Python Certificaton' to abc.txt file, which of the


following is valid code? ]
- A)f=open('abc.txt','b')f.write('Python Certificaton')f.close()
- B)f=open('abc.txt','r')f.write('Python Certificaton')f.close()
- C)f=open('abc.txt')f.write('Python Certificaton')f.close()
- D)f=open('abc.txt','w')f.write('Python Certificaton')f.close()

Q9. Consider the data present in the file: abc.txt

DURGASOFT,50,60,70,80,90 MICROSOFT,10,20,30,40,50 Which of the following


is valid code to read total data from the file? ]
- A)with open('abc.txt','r') f: data=f.read()
- B)with open('abc.txt') as f: data=f.read()
- C)with open('abc.txt','w') as f: data=f.read()
- D)with open('abc.txt') as f: data=f.readline()

You are writing an application that uses the sqrt function.The program
must reference the function using the name sq.
Which of the following import statement required to use? ]
- A) import math.sqrt as sq
- B) import sqrt from math as sq
- C) from math import sqrt as sq
- D) from math.sqrt as sq

You might also like