ComputerScience xi worksheet
ComputerScience xi worksheet
3) Assertion (A): Positional arguments in Python functions must be passed in the exact order in which
they are defined in the function signature.
Reasoning (R): Python functions automatically assign default values to positional arguments
4) Assertion (A): The strip() method removes all occurrences of a specific character from a string.
Reasoning (R): The strip() method removes characters only from the beginning and end of the
string.
9) Which of the following statement(s) would give an error during execution of the
following code?
tup = (20,30,40,50,80,79)
print(tup) #Statement 1
print(tup[3]+50) #Statement 2
print(max(tup)) #Statement 3
tup[4]=80 #Statement 4
10) Write a function countNow(PLACES) in Python, that takes the dictionary, PLACES
as an argument and displays the names (in uppercase)of the 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
12) Rao has written a code to input a number and check whether it is prime or not.
His code is having errors. Rewrite the correct code and underline the corrections
made. def prime(): n=int(input("Enter number to check :: ") for i in range (2, n//2): if n
%i=0: print("Number is not prime \n") break else: print("Number is prime \n’)
13) Write the Python statement for each of the following tasks using BUILT-IN
functions/methods only: (i) To insert an element 200 at the third position, in the list
L1.
14) (ii) To check whether a string named, message ends with a full stop / period or
not. 1+1= 2 [8] OR A list named studentAge stores age of students of a class. Write
the Python command to import the required module and (using built-in function) to
display the most common age value from the given list.
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())
c) 0
d) 3.14
e) -0.99
f) 2.718
g) "Hello, World!"
h) 'Python123'
i) "2024-12-07"
j) True
k) False
l) [1, 2, 3, 4]
m) ["apple", "banana", "cherry"]
n) [True, False, True]
o) (5, 10, 15)
p) ("red", "green", "blue")
q) (42, "age", True)
r) {"name": "Alice", "age": 25}
s) {"brand": "Ford", "model": "Mustang", "year": 1964}
t) {"Python": 3.9, "Java": 17, "C++": 14}
u) {1, 2, 3}
v) {"cat", "dog", "rabbit"}
w) {True, False}
x) None
y) 3 + 4j
z) -2 - 7j
29) Give two examples of each of the following: (III) unary and binary operators with eXample
30) compare: > with >> and < with << operators (II) Relational operators AND III Bitwise
31) EVALUATE result = (5 + 3 * 2) ** 2 / (8 - 4) + 6
i. value = 4 * (7 + 2) // 3 + (5 - 1) ** 2
34) Sure! Here’s another set of questions with built-in functions related to lists:
35) Given the following lists:
import random
x = random.randint(1, 10)
for i in range(0, x, 3):
print(i, end='$')
import random
letters = "HELLO"
z = random.randint(1, 5)
for i in range(0, z, 2):
print(letters[i], end='-')
import random
word = "Dreams"
n = random.randint(2, 7)
for i in range(1, n, 2):
print(word[i], end='%')
41) write a python program to to swap the first and last elements of a given tuple.
42) # Identify the syntax error in the following code:
for i in range(5):
print("Value:", i) # Output each value
43) # Identify and fix the indentation error:
x = 10
if x > 5:
print("x is greater than 5")
else:
print("x is 5 or less")
44) # Correct the code to resolve the syntax error:
def greet()
print("Hello, World!")
45) # Fix both the syntax and indentation errors in the code:
n = 4
while n > 0
print("Countdown:", n)
n -= 1
print("Blast off!")
46) # Identify and correct 1the syntax error:
numbers = [1, 2, 3, 4]1
for num in numbers
print(num)
56) 32. (a) Write the truth table for the given Boolean expression F=A’B’+A.C
57) Truth table for and,or and not gate and also nand and xor gate
58) Write the truth table for x+x’+y+y’ and also draw the circuit diagram also
65) lst[::-2] reverses the list and selects every second element.
66) Reversed list is [50,40,30,20,10][50, 40, 30, 20, 10][50,40,30,20,10], so selected elements are
[50,30,10][50, 30, 10][50,30,10].
67) Output Prediction: Random Module
68) import random
for i in range(3):
print(random.randint(1, 10))
line=[4,9,12,6,20]
for I in line:
for j in range(1,I%5):
print(j,’#’,end=””)
print()
70) Write a python program to create a list of integers entered by the user. Find and display the
largest and smallest numbers in the list. Calculate and display the sum of all prime elements
in the list
71) What ethical principles should be adhered to for safe and responsible internet browsing?
72) If t1 = (3,4,5,6,7,9) and t2 = ( 8,2 ),perform the following task
Print the elements first and last
Print the tuple t1 elements in reverse after sorting
Merge the tuples and print it without using extend function
i.