Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
19 views

1 output based question part with answer

Class 11 computer science notes and questions

Uploaded by

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

1 output based question part with answer

Class 11 computer science notes and questions

Uploaded by

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

OUTPUT BASED QUESTIONS

1 What will be the output of following string operations:


mysubject="Computer Science"
a) print(mysubject[0:len(mysubject)]) Computer Science
b) print(mysubject[-7:-1]) Scienc
c) print(mysubject[::2]) Cmue cec
d) print(mysubject[len(mysubject)-1]) e
e) print(2*mysubject) Computer ScienceComputer Science
f) print(mysubject[::-2]) eniSrtpo
g) print(mysubject[:3]+mysubject[3:]) Computer Science
2 What will be the output of following string operations:
myaddress="WZ-1, New Ganga Nagar, New Delhi"
a) print(myaddress.lower()) wz-1, new ganga nagar, new delhi
b) print(myaddress.upper()) WZ-1, NEW GANGA NAGAR, NEW DELHI
c) print(myaddress.count('New')) 2
d) print(myaddress.find('New')) 6
e) print(myaddress.split(',')) ['WZ-1', ' New Ganga Nagar', ' New Delhi']
f) print(myaddress.split()) ['WZ-1,', 'New', 'Ganga', 'Nagar,', 'New', 'Delhi']
g) print(myaddress.replace('New','Old')) WZ-1, Old Ganga Nagar, Old Delhi
h) print(myaddress.partition(',')) ('WZ-1', ',', ' New Ganga Nagar, New Delhi')
i) print(myaddress.index('Agra')) error
3 Consider the string str1=’Green Revolution’. Write statements in python to implement
the following:
a) To display the last four characters. str1[-4:]
b) To display the stating index for substring ‘vo’. str1.index(‘vo’)
c) To check whether the string contains ‘vol’ or not. ‘vol’ in str1
d) To repeat the string 3 times. srt1*3
4 Find the output of the following:
word='green vegetables'
print(word.find('g',2)) 8
print(word.find('veg',2)) 6
print(word.find('tab',4,15)) 10
print(word.find('eg',6,8)) -1
5 Find the output of the following code: mINDAwORKA
Text="Mind@Work!"
ln=len(Text)
nText=" "
for i in range(0,ln):
if Text[i].isupper():
nText=nText + Text[i].lower()
elif Text[i].isalpha():
nText=nText+Text[i].upper()
else:
nText=nText+"A"
print(nText)
6 Find the output of the following code: sELCcME&Cc
s="welcome2cs"
n = len(s)
m=""
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'):
m = m +s[i].upper()
elif (s[i] >= 'n' and s[i] <= 'z'):
m = m +s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m +'&'
print(m)

7 Find the output of the following code: SCE *3134


Text1="SSCE 2023"
Text2=""
I=0
while I<len(Text1):
if Text1[I]>="0" and Text1[I]<="9":
Val = int(Text1[I])
Val = Val + 1
Text2=Text2 + str(Val)
elif Text1[I]>="A" and Text1[I] <="Z":
Text2=Text2 + (Text1[I+1])
else :
Text2=Text2 + "*"
I=I+1
print(Text2)
8 Find the output of the following code: G*L*TME
Msg1="WeLcOME"
Msg2="GUeSTs"
Msg3=""
for I in range(0,len(Msg2)+1):
if Msg1[I]>="A" and Msg1[I]<="M":
Msg3=Msg3+Msg1[I]
elif Msg1[I]>="N" and Msg1[I]<="Z":
Msg3=Msg3+Msg2[I]
else:
Msg3=Msg3+"*"
print(Msg3)
List in Python
Q1 Suppose L=[“abc”,[6,7,8],3,’mouse’]
Consider the above list and answer the following:
(a) L[3:] ['mouse']
(b) L[::2] ['abc', 3]
(c) L[1:2] [6, 7, 8]
(d) L[1][1] 7
Q2 Write the output of the following :- [16, 15, 14, 1]
L=[]
L1=[]
L2=[]
for i in range(6,10):
L.append(i)
for i in range(10,4,-2):
L1.append(i)
for i in range(len(L1)):
L2.append(L[i]+L1[i])
L2.append(len(L)-len(L1))
print(L2)
Q3 Write the output of the following :-
(a) str1=”book” ['b', 'o', 'o', 'k']
print(list(str1))
(b) L = [2, 4, 5, 6, 2, 3, 4, 4, 7 ] 3
count = L.count(4)
print(count)

(c) L = [10,45,2,20,30,40]
[2, 10, 20, 30, 40, 45]
L.sort() [45, 40, 30, 20, 10, 2]
print(L)
L.reverse()
print(L)

(d) L=['p', 'w', 'r', 'd', 'a']


L.remove ('r') ['p', 'w', 'd', 'a']
print(L) a
['p', 'd']
print(L.pop())
del L[1]
print(L)

(e) L1 = [10, 20, 30, 40] []


L1.clear()
print(L1)

Q4 Write the output of the following:


L1=[500,600]
[500, 600, 700, 35, 45, 2]
L2=[35,45]
L1.append(700) [500, 600, 700, 35, 45, 2, 35, 45]
L1.extend(L2)
L1.insert(5,2) [500, 600, 700, 35, 45, 2]
print(L1) 3
print(L1+L2)
print(L1) [35, 45, 35, 45]
print(L1.index(35))
print(L2*2)
Q5 Suppose L=[10,['few','facts','fun'], 3,'Good']
Consider the above list and answer the following:
(i) L[3:] (ii) L[::2] (iii) L[1:2] (iv) L[1][1]
Ans:
(i) ['Good'] (ii) [10, 3]
(iii) [['few', 'facts', 'fun']] (iv) 'facts'
Q6 What will be the output of the following code segment?
i.myList = [1,2,3,4,5,6,7,8,9,10]
del myList[3:]
print(myList)
Ans: [1, 2, 3]

ii.myList = [1,2,3,4,5,6,7,8,9,10]
del myList[:5]
print(myList)
Ans: [6, 7, 8, 9, 10]
iii. myList = [1,2,3,4,5,6,7,8,9,10]
del myList[::2]
print(myList)
Ans:[2, 4, 6, 8, 10]
Q7 Write the output of the following Python program code:
Str2= list('Cam@123*')
for i in range(len(Str2)-1):
if i==5:
Str2[i] = Str2 [i]*2
elif (Str2[i].isupper()):
Str2[i] = Str2 [i]*2
elif (Str2 [i].isdigit()):
Str2[i] = 'D'
print(Str2)
Ans: ['CC', 'a', 'm', '@', 'D', '22', 'D', '*']
Q8 Write the output of the following Python program code:
STR1= list('SNo4')
for i in range(len(STR1)):
if i==3:
x=int(i)
x+=x-3
STR1[i]=x
elif (STR1[i].islower()):
STR1[i]=STR1[i].upper()
else:
STR1[i]=STR1[i]*2
print(STR1)
Ans: ['SS', 'NN', 'O', 3]

You might also like