0% found this document useful (0 votes)
30 views8 pages

Summer Holiday HW XII CS 2024-25

This document contains a series of questions and coding tasks related to Python programming, intended for a Computer Science summer holiday homework assignment for students. The questions cover various topics including data types, operators, functions, and error handling in Python. Additionally, it includes coding exercises that require the implementation of specific functions and algorithms.

Uploaded by

singhmanasmay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views8 pages

Summer Holiday HW XII CS 2024-25

This document contains a series of questions and coding tasks related to Python programming, intended for a Computer Science summer holiday homework assignment for students. The questions cover various topics including data types, operators, functions, and error handling in Python. Additionally, it includes coding exercises that require the implementation of specific functions and algorithms.

Uploaded by

singhmanasmay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

PM SHRI K V Greater Noida

XII Computer Science Summer Holiday HW , Session: 2024-25


Q Question
No
.
1 State True or False
“Tuple is datatype in Python which contain data in key-value pair.”
2 Which of the following is not a keyword?
(A) eval (B) assert
(C) nonlocal (D) pass
3 Given the following dictionaries
dict_student = {"rno" : "53", "name" : ‘Rajveer Singh’}
dict_marks = {"Accts" : 87, "English" : 65}
Which statement will merge the contents of both dictionaries?
(A) dict_student + dict_marks (B) dict_student.add(dict_marks)
(C) dict_student.merge(dict_marks) (D) dict_student.update(dict_marks)
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
5 Select the correct output of the code:
>>> s='mail2kv@kvsangathan.kvs.in'
>>> s=s.split('kv')
>>> op = s[0] + "@kv" + s[2]
>>> print(op)
(A) mail2@kvsangathan (B) mail2@sangathan .

(C) mail2@kvsangathan. (D) mail2kvsangathan.


6 Which of the following statement(s) would give an error after executing the following code?
D={'rno':32,'name':'Ms Archana','subject':['hindi','english','cs'],'marks':(85,75,89)} #S1
print(D) #S2
D['subject'][2]='IP' #S3
D['marks'][2]=80 #S4
print(D) #S5
(A) S1 (B) S3
(C) S4 (D) S3 and S4
7 What will the following expression be evaluated to in Python?
print ( round (100.0 / 4 + (3 + 2.55) , 1 ) )
(A) 30.0 (B) 30.55
(C) 30.6 (D) 31
8 (A) Given is a Python string declaration:
message='FirstPreBoardExam@2022-23'
Write the output of: print(message[ : : -3].upper())

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


d1={'rno':25, 'name':'dipanshu'}
d2={'name':'himanshu', 'age':30,'dept':'mechanical'}
d2.update(d1)
print(d2.keys())

9 Predict the output of the Python code given below:


data=["L",20,"M",40,"N",60]
times=0
alpha=""
add=0

for c in range(1,6,2):
times = times + c
alpha = alpha + data [c-1] + "@"
add = add + data[c]
print (times, add, alpha)
10 Predict the output of the Python code given below:
L=[1,2,3,4,5]
Lst=[]
for i in range(len(L)):
if i%2==1:
t=(L[i],L[i]**2)
Lst.append(t)
print(Lst)

11 Find the invalid identifier from the following


a) Marks@12 b) string_12 c)_bonus d)First_Name
12 Identify the valid declaration of Rec:
Rec=(1,‟Ashoka",50000)
a) List b) Tuple c)String d) Dictionary
13 Suppose a tuple Tup is declared as Tup = (12, 15, 63, 80) which of the following is incorrect?
a) print(Tup[1]) b) Tup[2] = 90
c) print(min(Tup)) d) print(len(Tup))
14 The correct output of the given expression is:
True and not False or False
(a) False (b) True (c) None (d) Null
t1=(2,3,4,5,6)
print(t1.index(4))
output is
(a) 4 (b) 5 (c) 6 (d) 2
15 Which of the following statement(s) would give an error after executing the following code?
x= int("Enter the Value of x:")) #Statement 1
for y in range[0,21]: #Statement 2
if x==y: #Statement 3
print (x+y) #Statement 4
else: #Statement 5
print (x-y) # Statement 6
(a) Statement 4 (b) Statement 5
(c) Statement 4 & 6 (d) Statement 1 & 2
16 (a) Given is a Python string declaration:
str="Kendriya Vidyalaya Sangathan"
Write the output of: print(str[9:17])
(b) Write the output of the code given below:
lst1 = [10, 15, 20, 25, 30]
lst1.insert( 3, 4)
lst1.insert( 2, 3)
print (lst1[-5])
17 Evaluate the following Python expression
print(12*(3%4)//2+6)
(a)12 (b)24 (c) 10 (d) 14
18 Fill in the Blank
The explicit conversion of an operand to a specific type is called _____
(a)Type casting (b) coercion (c) translation (d) None of these
19 Which of the following is not a core data type in Python?
(a)Lists (b) Dictionaries (c)Tuple (d) Class
20 What will the following code do?
dict={"Exam":"AISSCE", "Year":2022}
dict.update({"Year”:2023} )
a. It will create new dictionary dict={” Year”:2023}and old dictionary will be deleted
b. It will throw an error and dictionary cannot updated
c. It will make the content of dictionary as dict={"Exam":"AISSCE", "Year":2023}
d. It will throw an error and dictionary and do nothing
21 What will be the value of the expression : 14+13%15
22 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


(b) Statement 5 (d) Statement 4 and 5
23 What will be the output of the following expression?
24//6%3 , 24//4//2 , 48//3//4
a)(1,3,4) b)(0,3,4) c)(1,12,Error) d)(1,3,#error)
24 Write the output of following code and explain the difference between a*3 and (a,a,a)
a=(1,2,3)
print(a*3)
print(a,a,a)
25 Identify the invalid Python statement from the following.
(a) _b=1 (b) __b1= 1 (c) b_=1 (d) 1 = _b
26 Identify the valid arithmetic operator in Python from the following.
(a) // (b) < (c) or (d) <>
27 If Statement in Python is __
(a) looping statement (b) selection statement (c) iterative (d) sequential
28 Predict the correct output of the following Python statement – print(4 + 3**3/2)
(a) 8 (b) 9 (c) 8.0 (d) 17.5
29 Choose the most correct statement among the following –
(a) a dictionary is a sequential set of elements
(b) a dictionary is a set of key-value pairs
(c) a dictionary is a sequential collection of elements key-value pairs
(d) a dictionary is a non-sequential collection of elements
30 Consider the string state = “Jharkhand”. Identify the appropriate statement that will display the last five
characters of the string state?
(a) state [-5:] (b) state [4:] (c) state [:4] (d) state [:-4]
31 What will be the output of the following lines of Python code?
if not False:
print(10)
else:
print(20)
(a) 10 (b) 20 (c) True (d) False
32 Find error in the following code(if any) and correct code by rewriting code and underline the correction;‐
x= int(“Enter value of x:”)
for in range [0,10]:
if x=y
print( x + y)
else:
print( x‐y)
33 Find output generated by the following code:
Str = "Computer"
Str = Str[-4:]
print(Str*2)
34 Consider the following lines of codes in Python and write the appropriate output:
student = {'rollno':1001, 'name':'Akshay', 'age':17}
student['name']= “Abhay”
print(student)
35 Find output generated by the following code:
string="aabbcc"
count=3
while True:
if string[0]=='a':
string=string[2:]
elif string[-1]=='b':
string=string[:2]
else:
count+=1
break
print(string)
print(count)
36. Write a function to check if a number is a power of another number.

def isPower (x, y):

# The only power of 1


# is 1 itself
if (x == 1):
return (y == 1)

# Repeatedly compute
# power of x
pow = 1
while (pow < y):
pow = pow * x

# Check if power of x
# becomes y
return (pow == y)

37. Implement a function to generate all possible combinations of a list of integers.

# Program to print all combination


# of size r in an array of size n

# The main function that prints


# all combinations of size r in
# arr[] of size n. This function
# mainly uses combinationUtil()
def printCombination(arr, n, r):

# A temporary array to
# store all combination
# one by one
data = [0]*r;

# Print all combination


# using temporary array 'data[]'
combinationUtil(arr, data, 0,
n - 1, 0, r);

# arr[] ---> Input Array


# data[] ---> Temporary array to
# store current combination
# start & end ---> Starting and Ending
# indexes in arr[]
# index ---> Current index in data[]
# r ---> Size of a combination
# to be printed
def combinationUtil(arr, data, start,
end, index, r):

# Current combination is ready


# to be printed, print it
if (index == r):
for j in range(r):
print(data[j], end = " ");
print();
return;

# replace index with all


# possible elements. The
# condition "end-i+1 >=
# r-index" makes sure that
# including one element at
# index will make a combination
# with remaining elements at
# remaining positions
i = start;
while(i <= end and end - i + 1 >= r - index):
data[index] = arr[i];
combinationUtil(arr, data, i + 1,
end, index + 1, r);
i += 1;

38. Write a function to count the number of vowels in a string.

string = "GeekforGeeks!"
vowels = "aeiouAEIOU"

count = sum(string.count(vowel) for vowel in vowels)


print(count)

39. Create a function that generates a random password of a given length

import random
import string

def strong_level_pass(n):
# Random character generation
print("Strong level password: ", end="")
for i in range(n):
# Random special characters or digits
print(random.choice(string.ascii_letters + string.digits + string.punctuation), end="")
print()

40. Implement a function to find the maximum depth of nested lists.

def maxDepth(s):

count = 0
st = []

for i in range(len(s)):
if (s[i] == '('):
st.append(i) # pushing the bracket in the stack
elif (s[i] == ')'):
if (count < len(st)):
count = len(st)
# keeping track of the parenthesis and storing
# it before removing it when it gets balanced
st.pop()

return count

41. Write a function to check if a given string is a valid IPv4 address.

import re

# Function to check if the given string


# S is IPv4 or not
def checkIPv4(s):
# Count the occurrence of '.' in the given string
cnt = s.count('.')

# Not a valid IP address


if cnt != 3:
return False
# Split the string into tokens
tokens = s.split('.')

if len(tokens) != 4:
return False

# Check if all the tokenized strings


# lie in the range [0, 255]
for token in tokens:
# Base Case
if token == "0":
continue

if len(token) == 0:
return False

# Check if the tokenized string is a number


if not token.isdigit():
return False

# Range check for the number


if int(token) > 255 or int(token) < 0:
return False

return True

42. Create a function that finds the smallest missing positive integer in a list.

def solution(A): # Our original array

m = max(A) # Storing maximum value


if m < 1:

# In case all values in our array are negative


return 1
if len(A) == 1:

# If it contains only one element


return 2 if A[0] == 1 else 1
l = [0] * m
for i in range(len(A)):
if A[i] > 0:
if l[A[i] - 1] != 1:

# Changing the value status at the index of our list


l[A[i] - 1] = 1
for i in range(len(l)):

# Encountering first 0, i.e, the element with least value


if l[i] == 0:
return i + 1
# In case all values are filled between 1 and m
return i + 2

43. Write a function to find the longest common subsequence between two strings.

def lcs(X, Y, m, n):


if m == 0 or n == 0:
return 0
elif X[m-1] == Y[n-1]:
return 1 + lcs(X, Y, m-1, n-1)
else:
return max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n))

44. Implement a function to remove all occurrences of a specific element from a list

def remove_items(test_list, item):

# using list comprehension to perform the task


res = [i for i in test_list if i != item]
return res

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy