Questions Python Fundamentals

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

Ques 1) State True or False “Variable declaration is implicit in Python.

Ques 2) Which of the following is an invalid datatype in Python?

(a) Set (b) None (c)Integer (d)Real

Ques 3) Given the following dictionaries

dict_exam={"Exam":"AISSCE", "Year":2023}

dict_result={"Total":500, "Pass_Marks":165}
Which statement will merge the contents of both dictionaries?

a.) dict_exam.update(dict_result) b) dict_exam + dict_result

c) dict_exam.add(dict_result) d) dict_exam.merge(dict_result)

Ques 4) Consider the given expression: not True and False or True

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

(a) True (b) False (c) NONE (d) NULL

Ques 5) Select the correct output of the code:

a = "Year 2022 at All the best"


a = a.split('2')
b = a[0] + ". " + a[1] + ". " + a[3]
print (b)
(a) Year . 0. at All the best (b) Year 0. at All the best
(c) Year . 022. at All the best (d) Year . 0. at all the best
Ques 6) Which of the following statement(s) would give an error after executing the following
code?
S="Welcome to class XII" # Statement 1
print(S) # Statement 2
S="Thank you" # Statement 3
S[0]= '@' # Statement 4
S=S+"Thank you" # Statement 5
(a) Statement 3 (b) Statement 4 (c) Statement 5 (d) Statement 4 and 5

Ques 7) What will the following expression be evaluated to in Python? print(15.0 / 4 + (8 + 3.0))

(a) 14.75 (b)14.0 (c) 15 (d) 15.5

Ques 8)

(a) Given is a Python string declaration:


myexam="@@CBSE Examination 2022@@"
Write the output of: print(myexam[::-2])

(b) Write the output of the code given below:


my_dict = {"name": "Aman", "age": 26}
my_dict['age'] = 27
my_dict['address'] = "Delhi"
print(my_dict.items())
ques 9) Predict the output of the code given below:
s="welcome2cs"
n = len(s)
m=""
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'):
m = m +s[i].upper()
elif (s[i] >= 'n' and s[i] <= 'z'):
m = m +s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else: m = m +'&'
print(m)
ques 10) Find the invalid identifier from the following
a. none b. address c. Name d. pass
q) Consider a declaration L = (1, 'Python', '3.14').
Which of the following represents the data type of L?
a. list b. tuple c. dictionary d. string
ques 11) Given a Tuple tup1= (10, 20, 30, 40, 50, 60, 70, 80, 90).
What will be the output of print (tup1 [3:7:2])?
a. (40,50,60,70,80) b. (40,50,60,70) c. [40,60] d. (40,60)
Ques 12) The return type of the input() function is
a. string b. integer c. list d. tuple
Ques 13) Which of the following operator cannot be used with string data type?
a. + b. in c. * d. /
Ques 14) Consider a tuple tup1 = (10, 15, 25, and 30).
Identify the statement that will result in an error.
a. print(tup1[2]) b. tup1[2] = 20
c. print(min(tup1)) d. print(len(tup1))
Ques 15) Which one of the following is the default extension of a Python file?
a. .exe b. .p++ c. .py d. .p
Ques 16) Which of the following symbol is used in Python for single line comment?
a. / b. /* c. // d. #
Ques 17) What is the output of following code:
T=(100)
print(T*2)
a. Syntax error b. (200,) c. 200 d. (100,100)
Ques 18) Identify the output of the following Python statements.
x = [[10.0, 11.0, 12.0],[13.0, 14.0, 15.0]]
y = x[1][2]
print(y)
a. 12.0 b. 13.0 c. 14.0 d. 15.0
Ques 19) Identify the output of the following Python statements.
x=2
while x < 9:
print(x, end='')
x=x+1
a. 12345678 b. 123456789 c. 2345678 d. 23456789
Ques 20) Identify the output of the following Python statements.
b=1
for a in range(1, 10, 2):
b += a + 2
print(b)
a. 31 b. 33 c. 36 d. 39

Ques 21) Identify the output of the following Python statements.


lst1 = [10, 15, 20, 25, 30]
lst1.insert( 3, 4)
lst1.insert( 2, 3)
print (lst1[-5])
a. 2 b. 3 c. 4 d. 20
Ques 22) Evaluate the following expression and identify the correct answer.
16 - (4 + 2) * 5 + 2**3 * 4
a. 54 b. 46 c. 18 d. 32
Ques 23) What will be the output of the following code?
import random
List=["Delhi","Mumbai","Chennai","Kolkata"]
for y in range(4):
x = random.randint(1,3)
print(List[x],end="#")
a. Delhi#Mumbai#Chennai#Kolkata# b. Mumbai#Chennai#Kolkata#Mumbai#
c. Mumbai# Mumbai #Mumbai # Delhi# d. Mumbai# Mumbai #Chennai # Mumbai
Ques 24) Find the output of the following code:
Name="PythoN3.1"
R=""
for x in range(len(Name)):
if Name[x].isupper():
R=R+Name[x].lower()
elif Name[x].islower():
R=R+Name[x].upper()
elif Name[x].isdigit():
R=R+Name[x-1]
else:
R=R+"#"
print(R)
1) a. pYTHOn##@ b. pYTHOnN#@ c. pYTHOn#@ d. PYTHOnN#.
Ques 25) What will be the output of the following code?
tup1 = (1,2,[1,2],3)
tup1[2][1]=3.14
print(tup1)
a. (1,2,[3.14,2],3) b. (1,2,[1,3.14],3) c. (1,2,[1,2],3.14) d. Error Message
Ques 26) Find the invalid identifier from the following
a) MyName b) True c) 2ndName d) My_Name
Ques 27) Given the lists L=[1,3,6,82,5,7,11,92] , write the output of print(L[2:5])
Ques 28) Identify the valid arithmetic operator in Python from the following.
a) ? b) < c) ** d) and
Ques 29) Suppose a tuple T is declared as T = (10, 12, 43, 39),
which of the following is incorrect?
a) print(T[1]) b) T[2] = -29 c) print(max(T)) d) print(len(T))
Ques 30) Write a statement in Python to declare a dictionary whose keys are 1, 2, 3 and
values are Monday, Tuesday and Wednesday respectively.
Ques 31) A tuple is declared as T = (2,5,6,9,8) What will be the value of sum(T)?
Ques 32) Name the built-in mathematical function / method that is used to return an
absolute value of a number.
Ques 33) Identify the valid declaration of L:
L = [‘Mon’, ‘23’, ‘hello’, ’60.5’]
a. dictionary b. string c.tuple d. list
Ques 34) If the following code is executed, what will be the output of the following code?
name="ComputerSciencewithPython"
print(name[3:10])
Ques 35) Evaluate the following expressions:
a) 6 * 3 + 4**2 // 5 – 8
b) 10 > 5 and 7 > 12 or not 18 > 3
Ques 36) Rewrite the following code in Python after removing all syntax error(s).
Underline each correction done in the code.
Value=30
for VAL in range(0,Value)
If val%4==0:
print (VAL*4)
Elseif val%5==0:
print (VAL+3)
else
print(VAL+10)
Ques 37) State True or False: The Python interpreter handles logical errors during code
execution.
Ques 38) Identify the output of the following code snippet:
text = "PYTHONPROGRAM"
text=text.replace('PY','#')
print(text)
(A) #THONPROGRAM (B) ##THON#ROGRAM (C) #THON#ROGRAM (D)
#YTHON#ROGRAM
Ques 39) Which of the following expressions evaluates to False?
(A) not(True) and False (B) True or False (C) not(False and True) (D) True and not(False)
Ques 40) What is the output of the expression?
str='International'
print(str.split("n"))
(A) ('I', 'ter', 'atio', 'al') (B) ['I', 'ter', 'atio', 'al']
(C) ['I', 'n', 'ter', 'n', 'atio', 'n', 'al'] (D) Error
Ques 41) What will be the output of the following code snippet?
str= "World Peace"
print(str[-2::-2])
Ques 42) What will be the output of the following code?
tuple1 = (1, 2, 3)
tuple2 = tuple1
tuple1 += (4,)
print(tuple1 == tuple2)
(A) True (B) False (C)tuple1 (D)Error
Ques 43) If my_dict is a dictionary as defined below, then which of the following
statements will raise an exception?
my_dict = {'apple': 10, 'banana': 20, 'orange': 30}
(A) my_dict.get('orange')
(B) print(my_dict['apple', 'banana'])
(C) my_dict['apple']=20
(D) print(str(my_dict))
Ques 44) What does the list.remove(x) method do in Python?
(A) Removes the element at index x from the list
(B) Removes the first occurrence of value x from the list
(C)Removes all occurrences of value x from the list
(D)Removes the last occurrence of value x from the list
Ques 45) Which of the following statements will cause an error?
(A)t=1, (B) t=(1,) (C)t=(1) (D)t=tuple(1)
Ques 46) State whether the following statement is True or False: The finally block in Python
is executed only if no exception occurs in the try block.
Ques 47) Identify one mutable object and one immutable object from the following: (1,2),
[1,2], {1:1,2:2}, ‘123’
Ques 48) Give two examples of each of the following: (I) Arithmetic operators (II) Relational
operators
Ques 49) Identify the correct output(s) of the following code.
Also write the minimum and the maximum possible values of the variable b.
import random
a="Wisdom"
b=random.randint(1,6)
for i in range(0,b,2):
print(a[i],end='#')
Ques 50) If L1=[1,2,3,2,1,2,4,2, . . . ], and L2=[10,20,30, . . .], then
a) Write a statement to count the occurrences of 4 in L1.
b) Write a statement to sort the elements of list L1 in ascending order
c) Write a statement to insert all the elements of L2 at the end of L1
d) Write a statement to reverse the elements of list L2.
Ques 51) When is ZeroDivisionError exception raised in Python?
Ques 52) Give an example code to handle ZeroDivisionError? The code should display the
message "Division by Zero is not allowed" in case of ZeroDivisionError exception, and the
message "Some error occurred" in case of any other exception
Ques 53) When is NameError exception raised in Python?
Ques 54) Give an example code to handle NameError? The code should display the message
"Some name is not defined" in case of NameError exception, and the message "Some error
occurred" in case of any other exception.
Ques 55) What will be the output of the following
a,b,c = 11,22,33
a,b = c+2, a*3-b
print(a,b,c)
Ques 56)

Ques 57)
Ques) What will be the output of the following
a) print(‘xydsdssdaxy’,count(‘xy’))
b) print(‘xydsdssdaxy’,count(‘xy’,2))
Ques) What will be the output of the following
A= {}
A[2] = 1
A[1] = [2,3,4]
Print(A[1][1])
Ques) What will be the output of the following
for i in range(3) :
pass
print(i , end = ‘’)
Ques) What will be the output of the following
for i in range(3) :
break
print(i , end = ‘’)
Ques) What will be the output of the following
A= [1,2,3,4,5]
A.remove(4)
print(A)
Ques) What will be the output of the following
A= [1,2,3,4,5]
A.remove(A.index(3))
print(A)
Ques)
Book = {1: ‘Thriller’, 2: ‘Mystery’, 3: ‘Crime’, 4: ‘’Childern Stories}
Library = {‘5’:’Madras Diaries’, ‘6’: ‘Malgudi Days’}
Answer the following questions
a) Ramesh needs to change the title of dictionary book from ‘Crime’ to ‘Crime Thriller’
b) Write a code to merge the dictionary Book with library dictionary
c) What will be the output of following line of code
print(list(Library))

d)

Ques) Evaluate the following expression


a) 10 and 8
b) True or False and ‘Bye’
Ques) What will be the output of the following
print(2 ** (2 * (len(‘01’))))
Ques) What is the datatype of the X after the following statement execution
X = input(‘Enter the number’) if the input entered is 14
a) Float b) String c) Integer d) List
Ques) What will be the output of the following
X= [3,5,7,8]
X.insert(56,6)
Print(X)
Ques) What will be the output of the following
X = [5,4,3,2,1]
Print(x.pop(3))
Ques) What will be the output of the following
x = [5,4,3,2,1]
x.extend(x)
print(x)
Ques) What will be the output of the following
x = [44,33,44,66]
sorted(x)
print(x)
Ques) What will be the output of the following
L1 = [1,4,3,2]
L2= L1
L1.sort()
print(L2)
Ques) What is None?
Ans: - None keyword is used to define a null value or no value at all. None cannot be 0 or
empty string or False. Eg: - var = None print(var) The above code will print None.
Ques) What are the various mutable and immutable data types in Python ?
Ans: - The data types which are changeable called Mutable Data Type, and those which are
not changeable called immutable data types. Mutable Data types of Python are: - list,
dictionary, set Immutable Data Types are: - int, float, complex, string, tuple
Ques) Predict the output
for i in range( 1, 10, 3):
print(i)
Ques) What problem occurs with the following code
X=40
While X< 50 :
print(X)
Ques) Find the error in following code. State the reason of the error.
aLst = { ‘a’:1 ,’ b’:2, ‘c’:3 } print (aLst[‘a’,’b’])
Ques) S="PYTHON IS INTERPRETER BASED LANGUAGE" L=[83, 'Computer Science',
'PYTHON']
a) print(S) b) print(L) c) S[2]='K' d) print(S) e) L[0]=65 f) L[1]='IP' g) print(L)
Ques) For the following Python statement :
N = (25) What shall be the type of N ?
(A) Integer (B) String (C) Tuple (D) List
Ques)

You might also like