Assignment__I_XII_CS
Assignment__I_XII_CS
1. 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
2. Writ two possible outcome executed by the following code?
import random
PICK = random.randint (0,3)
CITY = [“DELHI”, “MUMBAI”, “CHENNAI”, “KOLKATA”]
for i in range (1, PICK):
for j in range (1, PICK):
print (i, end=” “)
print()
3. What will be the output of the following Python code?
def FunStr(S):
t=” “
for i in S:
if i.isdigit():
t=t+i
return t
X = “PYTHON 3.9”
Y = FunStr(X)
print (X, Y, sep = “*”)
a) PYTHON 3.9 c) PYTHON 3.9*39
b) PYTHON 3.9*3.9 d) Error
4. The code given below accepts a number as an argument and check whether a number
is palindrome or not. Observe the following code carefully and rewrite it after
removing all syntax and logical errors. Underline all the corrections made.
define palin(num):
rev = 0
rem = 0
while num>0:
rem = num/10
rev = rev*10+rem
num = num//10
if num1 = rev:
print (“It’s a palindrome”)
else:
print(“It is not a palindrome”)
5. Write a function countNow(PLACES) in Python that takes the dictionary places as an
argument and displays the number of places whose names are longer than 5
characters. For example, Consider the following dictionary
PLACES = {1: “Delhi”, 2: “London”, 3: “Paris”, 4: “New York”, 5: “Doha”}
The output should be:
LONDON
NEW YORK
6. Predict the output of the following code:
def ListChange ():
for i in range (len(L)):
if L[i] %2 == 0:
L[i] = L[i]*2
If L[i] %3 == 0:
L[i] = L[i]*3
else:
L[i]= L[i]*5
L = [2, 6, 9, 10]
ListChange()
for i in L:
print (i, end = “#”)
7. Output of the following expression:
(5<10) and (10<5) or (3<18) and not 8<18
a) 5 b) 18 c) False d) True
8. Write 2 possible outcomes executed from the following code?
import random
PICKER = random.randint (0,3)
COLOR = [“BLLUE”, “PINK”, “GREEN”, “RED”]
for i in color:
for j in range(1, PICKER):
print (i, end = “ “)
print()
9. What will be the output of the following Python code?
v = 50
def change (n):
global v
v, n = n, v
print (v, n, sep = “#”, end = “@”)
change (20)
print (v)
a) 200#50@20 b) 50@20#50 c) 50#50#50 d) 20@50#20
10. The following questions contains 2 statements: assertion and reasoning. Each question
has four choices – (i), (ii), (iii) and (iv) - only one of which is correct. In the light of
these statements, choose the most appropriate option.
(i) Both (A) and (R) are true and (R) is the correct explanation of (A)
(ii) Both (A) and (R) are true and (R) is not the correct explanation of (A)
(iii) (A) is true but (R) is false
(iv) (A) is false but (R) is true
Reason (R): Return statement passes back an expression to the caller return statement
with no arguments is the as return None.
11. The code given below accepts a number as an argument and returns maximum from a
list number. Observe the following code carefully and rewrite it after removing all
syntax and logical errors. Underline all the corrections made.
define max_num_in_list(list):
max = list[0]
for a in list:
if a == max:
max = a
return max
print (max_num_list([1, 2, -8, 0]))
12. Write a function count_vowel() which takes the string as a parameter having character.
The function should count number of rows in the string using the dictionary. The
function must return the dictionary to the calling program. Display the dictionary in
the calling program.
Example:
Input:
A quick brown fox jumps over the lazy dog.
Output:
“a” : 2, “e”: 1, “i” : 1, “o” : 4, “u” : 2
13. Consider List1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Write the Python statement for each of the following tasks using BUILT-IN
functions/methods only:
i) Remove last three elements from the list
ii) Add element 23 at index value 10
14. Predict the output of the following code:
def calc(u):
if u%2 ==0:
return u + 10
else:
return u + 2
def pattern (M, B = 2):
for CNT in range(0, B):
print(calc(CNT), M, end = “ “)
print()
pattern (“*”)
pattern (“#”, 4)
pattern (“@”, 3)
15. Can we pass a function as an argument in Python?