Page 383 - Computer Science Class 11 Without Functions
P. 383
Program 24
Consider a string blessing = 'Stay Happy n Healthy'. For each of the five rows of the following table,
write the appropriate slicing statement in the space provided in the table that produces the output given in the
second column.
Ans.
Verified Command
blessing[:6]
blessing[2:10:4]
blessing[3:10]
blessing[-1::-1]
blessing[-3:-12:-2]
Program 25
Consider the following strings:
Ans. code1 = 'Stay Safe'
code2 = 'stay alert and stay safe'
code3 = 'STAY AWARE'
code4 = '999999999'
code5 = 'Call@999'
code6 = 'Call999'
code7 = ' '
code8 = ' Be ethical '
code9 = 'safetyfirst'
For each of the commands given in the second column of the table given below, write the output in the third column
that will be produced on the execution of the statements (in the second column) by Python interpreter.
Sr. No. Command Output
1 code1.count('a') 2
2 code2.count('stay') 2
3 code3.count('a') 0
4 code1.lower() 'stay safe'
5 code3.lower() 'stay aware'
6 code2.upper() 'STAY ALERT AND STAY SAFE'
7 code2.title() 'Stay Alert And Stay Safe'
8 code2.capitalize() 'Stay alert and stay safe'
9 code8.strip() 'Be ethical'
10 code8.lstrip() 'Be ethical'
11 code8.rstrip() 'Be ethical'
12 code1.isupper() False
13 code3.isupper() True
14 code1.islower() False
Practical 381

