12 – COMPUTER SCIENCE
LESSON – 8
CODING WITH ANSWERS
WRITE THE OUTPUT OF THE FOLLOWING SNIPPETS. / பின்வரும் குறிமுறைகளின் வெளியீட்டை எழுதுக.
1) >>> print (‘I am the best student’)
I am the best student
2) >>> print ('Greater Chennai Corporation's student')
ERROR! (SyntaxError: invalid syntax )
3) str1 = "Chennai Schools"
str1[7] = "-"
ERROR! (Type error)
4) str1 = "Chennai Schools"
str1= "Delhi Schools"
print(str1)
Delhi Schools
5) s="How are you?"
print(s.replace("o","e"))
Hew are yeu?
6) s="How are you?"
s.replace("o","e")
print(s)
How are you?
7) str1=" Welcome to "
str1+="Learn Python"
print (str1*3)
Welcome to Learn Python Welcome to Learn Python Welcome to Learn Python
8) str1 = "Welcome to Government School"
print (str1[11:21])
print (str1[11:21:4])
print (str1[11:21:3])
print (str1[11:21:2])
print (str1[::3])
print (str1[::-3])
..1..
Government
Grn
Gemt
Gvrmn
Wceoore hl
lh erooecW
9) str1="TamilNadu"
print(str1[::-1]
udaNlimaT
10) str1="THIRUKKURAL"
print (str1[5])
print (str1[:5])
print (str1[5:])
K
THIRU
KKURAL
11) str1="COMPUTER"
index=0
for i in str1:
print (str1[:index+1])
index+=1
C
CO
COM
COMP
COMPU
COMPUT
COMPUTE
COMPUTER
12) str1="COMPUTER"
index=len(str1)
for i in str1:
print (str1[:index])
index-=1
..2..
COMPUTER
COMPUTE
COMPUT
COMPU
COMP
COM
CO
C
13) city="chennai"
print(city.capitalize())
print(city)
print(city.capitalize().swapcase())
Chennai
chennai
cHENNAI
14) str1="tech easy"
str2="Tech"
if str2 in str1:
print ("Found")
else:
print ("Not Found")
str4="tech"
if str4 in str1:
print ("Found")
else:
print ("Not Found")
Not Found
Found
15) str1=' * '
i=5
while i>=1:
print (str1*i)
i-=1
* * * * *
* * * *
* * *
* *
*
..3..
16) str1="ABCDEFGH"
str2="ate"
for i in str1:
print ((i+str2),end='\t')
Aate Bate Cate Date Eate Fate Gate Hate
17) str1 = "welcome"
str2 = "to school"
str3=str1[:2]+str2[len(str2)-2:]
print(str3)
weol
18) str1 = "welcome"
str2 = "to school"
str3=str1[3:]+str2[:len(str2)]
print(str3)
cometo school
19) str1='education department'
print(str1.capitalize())
print(str1.title())
print(str1.swapcase())
print(str1)
Education department
Education Department
EDUCATION DEPARTMENT
education department
20) str1="Welcome "
str1 + " by Tech Easy"
print(str1)
str1 += " by Tech Easy"
print(str1)
Welcome
Welcome by Tech Easy
21) str1="Tech Easy"
The positive index of the character ‘h’ is 3
The negative index of the character ‘h’ is -6
..4..