Modern School, Vasant Vihar
Fortnightly Assignment
Grade: Gr XI Chapter: String
Subject: Computer Science Date of Submission: Oct 30, 2024
1. Write a Python program to get a string made of the first 2 and the last 2 chars from a given a string. If the string
length is less than 2, return instead of the empty string.
Sample String: 'w3resource'
Expected Result: 'w3ce'
Sample String: 'w3'
Expected Result: 'w3w3'
Sample String: ' w'
Expected Result: Empty String
2. Write a Python program to get a single string from two given strings, separated by a space and swap the first
two characters of each string.
Sample String : 'abc', 'xyz'
Expected Result : 'xyc abz'
3. Write a Python function that takes as parameter to swap each character of a given string from lowercase to
uppercase and vice versa.
4. Write a Python program to count occurrences of a substring in a string.
5. Write a Python program to count and display the vowels of a given text.
6. Write a Python program to capitalize first and last letters of each word of a given string.
7. Write a program to convert a string with more than one word into title case string where string is passed as
parameter. (Title case means that the first letter of each word is capitalized.)
8. Write a program to generate the following pattern using String “Hello” & “World”:
Hell W H
o Wo ee
Hell Wor lll
Hel Worl llll
He World ooooo
H
9.Write a program in python that counts the number of individual words ‘to’ or ‘the’ (including upper and
lower cases) present in a multiline string.
For example: If the content of the string is
‘’’All goes to the temple
The train reached to Delhi
The journey to goa
The function should display’’’
Output should be -
Page 1 of 2
Count of to/the in string :6
Page 2 of 2