String_Program_Worksheet
String_Program_Worksheet
Subject: CS Grade: XI
Marks: Time:
Name: ___________ Date:
__________________________________________________________________
1. Write a Python program to get a string made of the first 2 and last 2 characters of a given string.
If the string length is less than 2, return the empty string instead.
3. 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.
4. Write a Python program to add 'ing' at the end of a given string (length should be at least 3). If
the given string already ends with 'ing', add 'ly' instead. If the string length of the given string is
less than 3, leave it unchanged.
5. Write a Python program to find the first appearance of the substrings 'not' and 'poor' in a given
string. If 'not' follows 'poor', replace the whole 'not'...'poor' substring with 'good'. Return the
resulting string.
Sample String : 'The lyrics is not that poor!'
6. Write a Python function that takes a list of words and return the longest word and the length of
the longest one.
Sample Output:
7. Write a Python program to change a given string to a newly string where the first and last chars
have been exchanged.
8. Write a Python program to remove characters that have odd index values in each string.
9. Write a Python function to get a string made of 4 copies of the last two characters of a specified
string (length must be at least 2).
Expected output :
o4
e3
u2
h2
11. Write a Python program to remove all characters except a specified character from a given
string.
Original string
Python Exercises
Original string
google
gg
Original string
exercises
Eee