CLASS: XII SUBJECT: COMPUTER SCIENCE
UNIT: I LESSON: STRINGS IN PYTHON No of session required: 1
Session Gist of Lesson Expected Teaching Suggested material / Assessment Worksheets
Learning Learning Resources strategies
Outcomes/ELO activities planned planned/Assignments
1 Strings: Traversal, Understands the Teacher will first Link of notes on
operations – basic concepts of of all give a 15-20 Strings from
concatenation, python minutes brief NCERT :- Link for Quiz :- WORKSHEET-1
repetition, programming Introduction of the https://
membership; involving Strings topic i.e. Strings in http://ncert.nic.in/
docs.google.com/
& manipulation of Python. textbook/pdf/
forms/d/e/
functions/methods– Strings in Python. kecs108.pdf
1FAIpQLSe6iwNYeoAryY
len(), capitalize(), Introduction: WORKSHEET-2
EGgKFVYDRRF8-
title(), upper(), Acquainted with
Strings in Python x5gr3Pb3h-
lower(), count(), various String
are stored as 5fA_v39bEou2g/
find(), functions & their
individual viewform?usp=sf_link
use.
index(), isalnum(), characters in WORKSHEET-3
islower(), isupper(), Familiar with contiguous Link for
isspace(), isalpha(), various locations, with two Video1(Strings Note: Teacher will
isdigit(), split(), programming way index for each Fundamentals) :- provide a common
syntax. location. email address to all
partition(), strip(), https://youtu.be/
students for the quiz
lstrip(), rstrip(), Identifies type of String Slice: It oBVq4GPQSQQ
to receive score or can
replace(); programming refers to part of
design their own
paradigm string where
String slicing. quiz’s in Google form
strings are sliced Link for
Applies the using a range of Video2(String
concept practically
indices. Slicing) :-
String Functions : https://youtu.be/ Link for
uqzSrRMxumw Assignment :-
Python offers
many built-in https://
functions and drive.google.com/
methods for string Link for Video3 file/d/
manipulation. (String Functions):- 15FvjdTIHvl8XrGSO
https://youtu.be/ Fj6QiDHGhAv8qw79
Link of PPT for /view?usp=sharing
Introduction :- dDTRl0F3kqE
https://
drive.google.com/
file/d/
1WZtAI5c6GSpze
vTTJL7NdYNZ0b Link for Assignment
hA_ZDH/view? Solution :-
usp=sharing
https://
drive.google.com/
Link for file/d/1b-
comprehensive QDdUbErbm46CIRe
PPT including all MZOxifVHAL1PQtq/
string functions & view?usp=sharing
examples :-
https://
drive.google.com/
file/d/1-
1p22FxWruK8WY
g7l7hW8yQQ5co
Vy1UP/view?
usp=sharing
WORKSHEET-1
NAME OF VIDYALAYA : ________________________________________________________________
NAME OF STUDENT : ______________________________ CLASS & SEC ________ROLL No__________
Q1 What will be the output of following code-
str="hello" str[:2]
Ans:
'he'
Q2 What will be the output of following code-
str='Hello' res=''
for i in range(len(str)):
res=res+str[i]
print(res)
Ans:
Hello
Q3 What will be the output of following code-
s='Hi!'
s1='Hello' s2=s[:2]+s1[len(s1)-2:] print(s2)
Ans:
Hilo
Q4 What will be the output of following code-
'ba'+'na'*2
Ans:
'banana'
Q5 What will be the output of following code-
s='Welcome to python4csip.com'
print(s.find('come'))
s.count('o')
Ans:
3
4
Q6 What will be the output of following program:
s='Hello'
for i in s:
print(i,end='#')
Ans:
H#e#l#l#o#
Q7 What will be the output of following program:
for i in 'hardik':
print(i.upper())
Ans:
H
A
R
D
I
K
Q8 What will be the output of following program: s='Hello'
for i in s:
print('Welcome')
Ans:
Welcome
Welcome
Welcome
Welcome
Welcome
Q9 What will be the output of following program: str='virat'
for i in str:
print(str.upper())
Ans: VIRAT
VIRAT
VIRAT
VIRAT
VIRAT
Q10 What will be the output of following program:
a='hello' b='virat'
for i in range(len(a)):
print(a[i],b[i])
Ans:
hv
ei
lr
la
ot
Q11 What will be the output of following program:
a='hello'
b='virat'
for i in range(len(a)):
print(a[i].upper(),b[i])
Ans:
HvEi
Lr
La
Ot
Q12 What will be the output of following program:
print("xyyzxyzxzxyy".count('xyy', 2, 11))
Ans:
0
Q13 What will be the output of following program:
print(“hello”+1+2+3)
Ans:
error
Q14 What will be the output of following program:
str1 = "PYTHON4CSIP.COM"
print(str1[1:4], str1[:5], str1[4:], str1[0:-1], str1[:-1])
Ans:
YTH PYTHO ON4CSIP.COM PYTHON4CSIP.CO PYTHON4CSIP.CO
Q15 What will be the output of following program:
str = "my name is kunfu pandya";
print (str.capitalize())
Ans:
My name is kunfu pandya
Q16 What will be the output of following program: str1 = 'Hello'
str2 ='World!'
print('str1 + str2 = ', str1 + str2)
print('str1 * 3 =', str1 * 3)
Ans:
str1 + str2 = HelloWorld!
str1 * 3 = HelloHelloHello
Q17 What will be the output of following program: count = 0
for letter in 'Hello World':
if(letter == 'l'):
count += 1
print(count,'letters found')
Ans:
3 letters found
Q18 What will be the output of following program:
s="python4csip"
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)
Ans:
ppyHho#CcIi
Q19 What will be the output of following program:
a = "Mahender Singh Dhoni"
a = a.split()
b = a[0][0]+". "+a[1][0]+". "+a[2]
print (b)
Ans:
M. S. Dhoni
Q20 What will be the output of following program: s='Mahender, Singh, Dhoni'
s1=s.split()
for i in s1:
print(i)
Ans:
Mahender,
Singh,
Dhoni
Q21 What will be the output of following program:
"Welcome to Python4csip.com".split()
Ans:
['Welcome', 'to', 'Python4csip.com']
Q22 What will be the output of following program: str ='Hello Python'
print (str) print (str[0])
print (str[2:8])
print (str[3:]) print (str * 3)
print (str + "String")
Ans:
Hello Python H
llo Py
lo Python
Hello PythonHello PythonHello Python Hello PythonString
Q23 What will be the output of the program?
line = "PYTHON IS EASY TO LEARN"
L = line.split('a')
for i in L:
print(i, end=' ')
Ans:
PYTHON IS EASY TO LEARN
Q24 What will be the output of following program:
s='mahender, singh, dhoni'
s1=s.split()
for i in s1:
if(i>'n'):
print(i.upper())
else:
print(i)
Ans:
mahender,
SINGH,
dhoni
Q25 What will be the output of following program:
my_string = 'PYTHON4CSIP'
for i in range(len(my_string)):
print (my_string)
my_string = '#'
Ans:
PYTHON4CSIP
#
#
#
#
#
#
#
#
#
#
Q26 What will be the output of following program:
str="Python4csip.com"
for i in range(len(str)):
if(str[i].isalpha()):
print(str[i-1],end='')
if(str[i].isdigit()):
print(str[i],end='')
Ans:
mPytho44csi.co
Q27 What will be the output of following program:
str="AB145CVD124N"
for i in range(len(str)):
if(str[i].isalpha()):
print(str[i-1],end='')
if(str[i].isdigit()):
print('#',end='')
Ans:
NA###5CV###4
Q28 What will be the output of following program:
str="PYTHON4CSIP"
for i in range(len(str)):
if(str[i].isdigit()):
print(str[i],end='')
if(str[i]=='N'or str[i]=='Y'):
print('#',end='')
Ans:
##4
WORKSHEET-2
NAME OF VIDYALAYA :_______________________________________________________________
NMAE OF STUDENT: ___________________________ CLASS & SEC: __________ ROLL No ________
Q1 Write a Program to Count the Number of Vowels in a String.
Ans:
string=input("Enter string:")
vowels=0
for i in string:
if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u' or i=='A' or i=='E' or i=='I' or i=='O' or
i=='U'):
vowels=vowels+1
print("Number of vowels are:")
print(vowels)
Q2 Write a Program to Take in a String and Replace Every Blank Space with Hyphen.
Ans:
string=input("Enter string:")
string=string.replace(' ','-')
print("Modified string:")
print(string)
Q3 Write a Program to Calculate the Length of a String Without Using a Library Function
Ans:
string=input("Enter string:")
count=0
for i in string:
count=count+1
print("Length of the string is:")
print(count)
Q4 Write a Program to Calculate the Number of Words and the Number of Characters
Present in a String
Ans:
string=input("Enter string:")
char=0
word=1
for i in string:
char=char+1
if(i==' '):
word=word+1
print("Number of words in the string:")
print(word)
print("Number of characters in the string:")
print(char)
Q5 Write a Program to Take in Two Strings and Display the Larger String without Using
Built-in Functions
Ans:
string1=input("Enter first string:")
string2=input("Enter second string:")
count1=0
count2=0
for i in string1:
count1=count1+1
for j in string2:
count2=count2+1
if(count1<count2):
print("Larger string is:")
print(string2)
elif(count1==count2):
print("Both strings are equal.")
else:
print("Larger string is:")
print(string1)
Q6 Write a Program to Count Number of Lowercase Characters in a String
Ans:
string=input("Enter string:")
count=0
for i in string:
if(i.islower()):
count=count+1
print("The number of lowercase characters is:")
print(count)
Q7 Write a Program to Check if a String is a Palindrome or Not
Ans:
string=input("Enter string:")
if(string= =string[::-1]):
print("The string is a palindrome")
else:
print("The string isn't a palindrome")
Q8 Write a Program to Calculate the Number of Upper Case Letters and Lower Case
Letters in a String
Ans:
string=input("Enter string:")
count1=0
count2=0
for i in string:
if(i.islower()):
count1=count1+1
elif(i.isupper()):
count2=count2+1
print("The number of lowercase characters is:")
print(count1)
print("The number of uppercase characters is:")
print(count2)
Q9 Write a Program to Calculate the Number of Digits and Letters in a String.
Ans:
string=input("Enter string:")
count1=0
count2=0
for i in string:
if(i.isdigit()):
count1=count1+1
count2=count2+1
print("The number of digits is:")
print(count1)
print("The number of characters is:")
print(count2)
Q10 Write a Program to Form a New String Made of the First 2 and Last 2 characters From a
Given String
Ans:
string=input("Enter string:")
count=0
for i in string:
count=count+1
new=string[0:2]+string[count-2:count]
print("Newly formed string is:")
print(new)
Q11 Write a Program to Count the Occurrences of Each Word in a Given String Sentence
Ans:
string=input("Enter string:")
word=input("Enter word:")
a=[]
count=0
a=string.split(" ")
for i in range(0,len(a)):
if(word==a[i]):
count=count+1
print("Count of the word is:")
print(count)
Q12 Write a Program to Check if a Substring is Present in a Given String
Ans:
string=input("Enter string:")
sub_str=input("Enter word:")
if(string.find(sub_str)==-1):
print("Substring not found in string!")
else:
print("Substring found in string!")
Q13 Write a Python Program to check First Occurrence of a Character in a String
Ans:
string = input("Please enter your own String : ")
char = input("Please enter your own Character : ")
flag = 0
for i in range(len(string)):
if(string[i] == char):
flag = 1
break
if(flag = = 0):
print("Sorry! We haven't found the Search Character in this string ")
else:
print("The first Occurrence of ", char, " is Found at Position " , i + 1)
Q14 Write a Python Program to find ASCII Value of a Character
Ans:
ch = 'T'
print("The ASCII Value of %c = %d" %(ch, ord(ch)))
Q15 Write a Python Program to Remove Last Occurrence of a Character in a String
Ans:
string = input("Please enter your own String : ")
char = input("Please enter your own Character : ")
string2 = ''
length = len(string)
for i in range(length):
if(string[i] == char):
string2 = string[0:i] + string[i + 1:length]
print("Original String : ", string)
print("Final String : ", string2)
WORKSHEET-3
Q1 How are lists different from strings when both are
. sequences? NAME OF VIDYALAYA:
Q2 How are tuples different from lists when both are
. sequences?
Q3 Write a program that takes a string with multiple
. words and then capitalizes the first letter of each word
and forms a new string out of it.
Q4 Write a program that checks whether entered string is
. palindrome or not.
Q5 Write a program to print alternate characters in a
. String where string is entered by the user.
_____________________________________________________
NAME OF STUDENT: ________________________CLASS & SEC: ___________ ROLL NO______