11 CSWTJan 2023 MS
11 CSWTJan 2023 MS
11 CSWTJan 2023 MS
6. Identify the Python statements, that will produce identical output: [1]
a) print('faips'.swapcase()); print('faips'.upper())
b) print('FaIpS'.swapcase()); print('fAiPs'.lower())
c) print('FaIpS'.swapcase()); print('fAiPs'.upper())
d) print('FaIpS'.upper()); print('fAiPs'.lower())
9. Rewrite the program after removing all the errors. Underline the corrections. [2]
numlist=[] numlist=[]
for x in range(1:11): for x in range(1,11):
num=eval(input('Value? ') num=eval(input('Value? '))
numlist+=num numlist+=[num]
print(sum(nlist)) print(sum(numlist))
Page 1/3
Class XI Second Term Computer Science Weekly Test 2022-23 Marking Scheme
10. Give the output of the Python program given below: [1]
weekend='FRIDAY-SATURDAY'
YRAYI
print(weekend[::-3])
SATUR
print(weekend[-8:12])
11. After the execution of Python program given below, what will be the correct output(s)? What will be
the maximum value and minimum value stored in the variable index? [2]
from random import randint
Possible correct outputs
vowels=['Ae', 'Uu', 'Ee', 'Oo', 'Ii']
a) EeOoIi b) UuEeOo
for x in range(2, 5):
index=randint(1, x) index Min: 1
print(vowels[index],end='') index Max: 4
a) EeOoIi b) UuEeOo c) IiOoEe d) EeAaIi
12. Give the output of the Python program given below: [2]
mylist=[123, 234, 345, 456] 135
for k in range(len(mylist)): 257
mylist[k]+=mylist[k]//10 379
for num in mylist: 501
print(num)
13. Write a Python program to input a string. Obtain a new string by toggling the case of letters
(uppercase to lowercase and vice-versa) present in the inputted string. Display the converted string.
You are only allowed to use input(), print(), chr() and ord(). [4]
Suppose inputted string contains 'GH-14/873 PASCHIM ViHaR'
The new toggled string should be 'gh-14/873 paschim vIhAr'
mystr=input('Input a string? ')
newstr=""
for ch in mystr:
if 'A'<=ch<='Z': ch=chr(ord(ch)+32)
elif 'a'<=ch<='z': ch=chr(ord(ch)-32)
newstr+=ch
print('Toggled String=', newstr)
14. Write a Python program to input a string. Check whether the inputted string is a Palindrome or not.
A Palindrome string reads same from left to right and right to left. You are only allowed to use
input() and print() functions.
[3]
mystr=input('Input a string? ')
newstr=""
for ch in mystr:
newstr=ch+newstr
if mystr==newstr:
print(mystr, 'Palindrome')
else:
print(mystr, 'Not Palindrome')
15. Write a Python program to create a tuple by inputting n (n is a user inputted value) floating point
values from the keyboard during the run-time. Calculate and display harmonic mean of floating
point values present in the tuple. You are only allowed to use input(), print() and len() functions.
[4]
If inputted values contained in the tuple are 1.2, 6.3, 4.4, 3.7, 2.8 then the Harmonic mean is
Page 2/3
Class XI Second Term Computer Science Weekly Test 2022-23 Marking Scheme
5
=1.85
1 1 1 1 1
+ + + +
1.2 6.3 4.4 3.7 2.8
n=int(input('Input Number of values? '))
nlist=()
for x in range(n):
val=eval(input('Input a value? '))
nlist+=(val,)
s=0
for num in nlist:
s+=1/num
hm=n/s
print('Harmonic Mean=', hm)
16. Write a Python program to create a list with n 4-digit random integer values, where n is a user
inputted value. Calculate and display the sum and average of elements which are neither divisible 3
nor divisible by 5. You are only allowed to use functions from random module, input() and print().
[4]
from random import randint
n=int(input('Input Number of values? '))
alist=[randint(1000,9999) for x in range(n)]
s=c=0
for num in alist:
if num%3!=0 and num%5!=0:
s+=num
c+=1
avg=s/c
print('Sum=', s)
print('Average=', avg)
Page 3/3