Rev 1 _ q With Ans _python Basics and Flow Control 17.08.24
Rev 1 _ q With Ans _python Basics and Flow Control 17.08.24
General Instructions:
SECTION A 18 X 1 = 18 Marks
Answer is : a
6. If you want to display the values without decimal place after division, which of the 1
following symbol is used?
a. / b. // c. % d. **
Answer is : b
7. 1. Which of the is a correct statement? 1
Answer : c
8. 1
Which of the following is not a keyword?
a) Eval b) assert c) nonlocal d) pass
Answer : a)
Answer : a
10 3. What will be the value of X in the following Python expression?
X = 2+9*((3*12)-8)/10
a) 30.0 b) 30.8 c) 28.4 d) 27.2
Answer : d
Answer : a
Answer : b
Answer : c
14 T=(“See You”) What is the data type of T?
a)tuple b)string c)List d)set
Answer : b
15 Assertion(A):An identifier may be combination of letters and numbers.
Reason(R):No special symbols are permitted in an identifier name
a)Both A and R are True and R is the correct explanation for A
b) Both A and R are True and R is not the correct explanation for A
c)A is True but R is False
Answer : C
16 Which of the following is not considered a valid identifier in Python:
a) three3
b) _main
c) hello_kv1
d) 2 thousand
Answer : d
Answer : d
Answer: b
SECTION – B [ 7 X 2 = 14 Marks ]
19. Give the output of the following when num1 = 4, num2 = 3, num3 = 2 2
Ans :9
b) num1 = num1 ** (num2 + num3)
print (num1)
Ans : 1024
Ans : a) 9 b)
20 In how many ways, can you work in Python? What is the difference between them? 2
Ans-In two ways we can work in Python- (i) Interactive mode (ii) Script Mode
In interactive mode, one command can run at a time and commands are not
saved. Whereas in Script mode, we can save all the commands in the form of a
program file and can see output of all lines together.
21 How many types of sequences are supported in Python? List with 2
examples.
Ans: Three Types of Sequences are supported in python: (i) String (ii) List (iii)
Tuple
22 Give the output of the following 2
Sum = 0
for k in range(5):
Sum = Sum+k
print(Sum)
Ans : 10
23 Give the output of the following 2
Sum = 0
for k in
range(10 , 1, -2):
Sum = Sum+k
print(Sum)
Ans : 30
24 Give the output of the following 2
for k in range(4):
for j in range(k):
print(‘*’, end = ‘ ‘)
print()
Ans :
*
**
***
25 Write the ouput of the following code:- 2
Text = "gmail@com"
L=len(Text)
Ntext=""
for i in range(0,L):
if Text[i].isupper():
Ntext=Ntext+Text[i].lower()
elif Text[i].isalpha():
Ntext= Ntext+Text[i].upper()
else:
Ntext=Ntext+'bb'
print(Ntext)
Ans :
GMAILbbCOM
SECTION – C [ 5 X 3 = 15 Marks ]
26 Define Data Type. Explain mutable and immutable objects in python with 3
examples.
Answer :
28 Rewrite the following code in python after removing all syntax error(s). Underline 3
each correction done in the code.
30=To
for K in range(0,To)
IF k%4==0:
print (K*4)
Else:
print (K+3)
29 Rewrite the following code after removing all syntax error(s) and underline each 3
correction done:
Runs=(10,5,0,2,4,3)
for I in Runs:
if I=0:
print(Maiden Over)
else:
print(Not Maiden)
30 Write the python program to print the index of the character in a string. 3
Answer :
string1 = input("enter string")
for i in range(len(string1)):
print("current character",string1[i],"position at",i)
SECTION – D [ 3 X 5 = 15 Marks ]
31 What do you mean by Debugging? Explain it’s categories. 5
32 What is the use of else statement in for loop and in while loop ? Explain. 5
Answer :
Else with loop is used with both while and for loop. The else block is executed at the
end of loop means when the given loop condition is false then the else block is
executed.
i=0
while i<5:
i+=1
print("i =",i)
else:
print("else block is executed")
Explanation
declare i=0
we know then while loop is active until the given condition is true. and we check
i<5 it’s true till the value of i is 4.
i+=1 increment of i because we don’t want to execute the while loop infinite
times.
print the value of i
else block execute when the value of i is 5.
l = [1, 2, 3, 4, 5]
for a in l: print(a)
else:
print("else block is executed")
Explanation
declare a list l=[1,2,3,4,5]
for loop print a.
else block is execute when the for loop is read last element of list.
SECTION – E [ 2 X 4 = 8 Marks ]
34 Write Python code to find whether the given item is present in the given list using 4
for loop.
Answer:
flag = 0
L = eval(input(‘input a list on numbers’)
E = int(input(‘item to be searched’)
K =len(L)
for p in range(K):
if E ==L(p):
flag = 1
print(‘found and
index is ‘,p)
if flag==0:
print(‘not found’)
35 Differentiate between break and continue statement used in python with examples. 4
Answer :
The break statement terminates the current loop , i.e the loop in which it appears, and
resumes execution at the next statement immediately after the end of that loop.if break
statement is inside a nested loop(loop inside another loop), break will terminate the
innermost loop.
When a continue statement is encountered, the control jumps to the beginning of the
loop for next iteration, thus skipping the execution of statements inside the body of
loop for the current iteration. As usual, the loop condition is checked to see if the loop
should continue further or terminate. If the condition of the loop is entered again, else
the control is transferred to the statement immediately following the loop.