Delhi Public School Ruby Park, Kolkata
WorksHeet
Subject: Computer Science Class: XI
Chapter: Strings
Programming Questions
Basic Programs
1. Write a program to count the number of times a character occurs in a given string.
2. Write a program to input a string and print it in reverse order in-place (without using slicing or creating a new string).
3. Write a program to input a string and print it in reverse using a for loop.
4. Write a program to input a string and check if the string is palindrome or not.
Definition A string is called palindrome if it reads the same backwards as forward, mom is a palindrome.
5. Write a program that asks the user for a string (only single space between words) and returns an estimate of how many
words are in the string.
Moderate Programs
6. Write a program which accepts a string and replaces all vowels in the string with “#”.
7. Write a program that inputs a line of text and prints out the count of vowels in it.
8. Write a program to input lines of the text from the user until enter is pressed. Count the total number of characters in
the text(including white spaces), total no. of digits, total number of special symbols and total no. of words in the given
text. Assume each word is separated by one space.
9. Write a program to input lines of text and apply the title function if entered text has more than one word.
10. Write a program to input a text of lines. Assume each word is separated by one space. Replace space with “-”.
11. Write a program that should prompt the user to type some sentence(s) followed by “enter”. It should then print the
original sentence(s) and the following statistics relating to the sentence(s):
(a) Number of words
(b) Number of characters (including white-space and punctuation)
(c) Percentage of characters that are alphanumeric
12. Write a Python program as per specifications given below:
(a) Repeatedly prompt for a sentence (string) or for ‘q’ to quit.
(b) Upon input of a sentence s, print the string produced from s by converting each lower case letter to upper case and
each upper case letter to lower case.
(c) All other characters are left unchanged.
13. Write a program to input a line of text and print the biggest word (length wise) from it.
Advanced Programs
14. Write a program to input a string and character and delete the occurrence of the character in the given string.
15. Write a program to input a string having some digits. Print the sum of digits present in its string.
16. Write a program that should do the following :
(a) prompt the user for a string
(b) extract all the digits from the string
Delhi Public School Ruby Park, Kolkata XI – 083 – Computer Science Chapter: Strings
(c) If there are digits:
i. sum the collected digits together
ii. print out the original string, the digits, the sum of the digits
(d) If there are no digits:
i. print the original string and a message “has no digits”
17. Write a program to input a line of text and create a new line of text where each word of input line is reversed.