1.
String Input Print
Write a program in python to input a string and print it.
Test Data :
Input the string : Welcome, w3resource
Expected Output :
The string you entered is : Welcome, w3resource
2. String Length Without Library
Write a program in python to find the length of a string without using library
functions.
Test Data :
Input the string : [Link]
Expected Output :
Length of the string is : 15
3. Separate String Characters
Write a program in python to separate individual characters from a string.
Test Data :
Input the string : [Link]
Expected Output :
The characters of the string are :
w 3 r e s o u r python e . python o m
4. Reverse String Characters
Write a program in python to print individual characters of a string in reverse
order.
Test Data :
Input the string : [Link]
Expected Output :
The characters of the string in reverse are :
m o python . e python r u o s e r 3 w
5. Count Words in String
Write a program in python to count the total number of words in a string.
Test Data :
Input the string : This is [Link]
Expected Output :
Total number of words in the string is : 3
6. Compare Strings Without Library
Write a program in python to compare two strings without using string library
functions.
Test Data :
Check the length of two strings:
--------------------------------
Input the 1st string : aabbcc
Input the 2nd string : abcdef
String1: aabbcc
String2: abcdef
Expected Output : Strings are not equal.
Check the length of two strings:
--------------------------------
Input the 1st string : aabbcc
Input the 2nd string : aabbcc
String1: aabbcc
String2: aabbcc
Expected Output : Strings are equal.
7. Count Alphabets, Digits, Specials
Write a program in python to count the total number of alphabets, digits and
special characters in a string.
Test Data :
Input the string : Welcome to [Link]
Expected Output :
Number of Alphabets in the string is : 21
Number of Digits in the string is : 1
Number of Special characters in the string is : 4
8. Copy String
Write a program in python to copy one string to another string.
Test Data :
Input the string : This is a string to be copied.
Expected Output :
The First string is : This is a string to be copied.
The Second string is : This is a string to be copied.
Number of characters copied : 31
9. Count Vowels and Consonants
Write a program in python to count the total number of vowels or consonants in a
string.
Test Data :
Input the string : Welcome to [Link]
Expected Output :
The total number of vowel in the string is : 9
The total number of consonant in the string is : 12
10. Maximum Frequency Character
Write a program in python to find the maximum number of characters in a string.
Test Data :
Input the string : Welcome to [Link].
Expected Output :
The Highest frequency of character 'e'
appears number of times : 4
11. Sort String Array
Write a python program to sort a string array in ascending order.
Test Data :
Input the string : w3resource
Expected Output :
After sorting the string appears like :
3ceeorrsuw
12. Bubble Sort String
Write a program in python to read a string from the keyboard and sort it using
bubble sort.
Test Data :
Input number of strings :3
Input string 3 :
zero
one
two
Expected Output :
The strings appears after sorting :
one
two
zero
13. Extract Substring
Write a program in python to extract a substring from a given string.
Test Data :
Input the string : this is test string
Input the position to start extraction :9
Input the length of substring :4
Expected Output :
The substring retrieve from the string is : " test "
14. Check Substring Presence
Write a python program to check whether a substring is present in a string.
Test Data :
Input the string : This is a test string.
Input the substring to be search : search
Expected Output :
The substring is not exists in the string.
15. Toggle Case of Sentence
Write a program in python to read a sentence and replace lowercase characters
with uppercase and vice versa.
Test Data :
Input the string : This Is A Test String.
Expected Output :
The given sentence is : This Is A Test String.
After Case changed the string is: tHIS iS a tEST sTRING.
16. Count Word Occurrences
Write a program in python to find the number of times a given word 'the' appears
in the given string.
Test Data :
Input the string : The string where the word the present more than once.
Expected Output :
The frequency of the word 'the' is : 3
17. Remove Non-Alphabets
Write a program in python to remove characters from a string except alphabets.
Test Data :
Input the string : [Link]
Expected Output :
After removing the Output String : wresourcecom
18. Frequency of a Character
Write a program in python to find the frequency of characters.
Test Data :
Input the string : This is a test string
Input the character to find frequency: i
Expected Output :
The frequency of 'i' is : 3
19. Concatenate Strings Manually
Write a program in python to combine two strings manually.
Test Data :
Input the first string : this is string one
Input the second string : this is string two
Expected Output :
After concatenation the string is :
this is string one this is string two
20. Largest and Smallest Word
Write a program in python to find the largest and smallest words in a string.
Test Data :
Input the string : It is a string with smallest and largest word.
Expected Output :
The largest word is 'smallest'
and the smallest word is 'a'
in the string : 'It is a string with smallest and largest word.'.
21. Convert String to Uppercase
Write a program in python to convert a string to uppercase.
Test Data :
Input a string in lowercase : the quick brown fox jumps over the lazy dog
Expected Output :
Here is the above string in UPPERCASE :
THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.
22. Convert String to Lowercase
Write a program in python to convert a string to lowercase.
Test Data :
Input a string in UPPERCASE : THE QUICK BROWN FOX JUMPS OVER THE
LAZY DOG.
Expected Output :
Here is the above string in lowercase :
the quick brown fox jumps over the lazy dog.
23. Check Hexadecimal Digit
Write a program in python to check whether a character is a Hexadecimal Digit or
not.
Test Data :
Input a character : 7
Expected Output :
The entered character is a hexadecimal digit.
24. Check Uppercase Letter
Write a program in python to check whether a letter is uppercase or not.
Test Data :
Input a character : p
Expected Output :
The entered letter is not an UPPERCASE letter.
25. Replace Spaces with Specific Character
Write a program in python to replace the spaces in a string with a specific
character.
Test Data :
Input a string : Be glad to see the back of Input replace character : *
Expected Output :
After replacing the space with * the new string is :
Be*glad*to*see*the*back*of*
26. Count Punctuation Characters
Write a program in python to count the number of punctuation characters present
in a string.
Test Data :
Input a string : The quick brown fox, jumps over the, lazy dog.
Expected Output :
The punctuation characters exists in the string is : 3
27. Print String Before Newline
Write a program in python to print only the string before the new line character.
Note: isprint() will only print line one, because the newline character is not
printable.
Expected Output :
The quick brown fox
28. Check Lowercase Letter
Write a program in python to check whether a letter is lowercase or not.
Test Data :
Input a character : w
Expected Output :
The entered letter is a lowercase letter.
29. Remove Spaces from File Content
Write a program in python to read a file and remove the spaces between two
words of its content.
Expected Output :
The content of the file is :
The quick brown fox jumps over the lazy dog
After removing the spaces the content is :
Thequickbrownfoxjumpsoverthelazydog
30. Check Digit Character
Write a program in python to check whether a character is a digit or not.
Test Data :
Input a character : 8
Expected Output :
The entered character is a digit.
31. Split String by Spaces
Write a program in python to split strings by space into words.
Test Data :
Input a string : this is a test string
Expected Output :
Strings or words after split by space are :
this
is
a
test
string .
32. Find Repeated Character
Write a python program to find the repeated character in a string.
Test Data :
Input a string: w3resource
Expected Output:
Input a string: The first repetitive character in w3resource is:
r
33. Count Each Character Occurrence
Write a python program to count each character in a given string.
Test Data :
Input a string: w3resource
Expected Output:
Enter a str1ing: The count of each character in the string
w3resource is
w 1
3 1
r 2
e 2
s 1
o 1
u 1
c 1
34. Uppercase Vowels in String
Write a python program to convert vowels into uppercase characters in a string.
Test Data :
Input a string : w3resource
Expected Output:
Input a sentence: The original string:
w3resource
After converting vowels into upper case the sentence becomes:
w3rEsOUrcE
35. Longest Substring Without Repeating
Write a python program to find the length of the longest substring of a given
string without repeating characters.
Test Data :
Input a string: “abcddefffd”
Expected Output:
Input a string: Length of the longest substring without repeating
characters: 4
36. Validate Bracket String
A given string contains the bracket characters '(', ')', '{', '}', '<', ‘>', '[' and ']', Write a
python program to check if the string is valid or not. The input string will be valid
when open brackets and closed brackets are same type of brackets.
Test Data :
Input a string: <>()[]{}
Expected Output:
Check bracket in the said string is valid or not? 1
37. Multiply Numbers as Strings
Write a python program to multiply two positive numbers as strings. Return a
string representation of the product.
Expected Output:
Original numbers: 100 and 15
Multiple two said numbers represent as string? 1500
38. Reverse Vowels in String
Write a python program to reverse all the vowels present in a given string. Return
the newly created string.
Test Data :
Input a string: “AEIou”
Expected Output:
Input a string: Check bracket in the said string is valid or not?
“uoIEA”
39. Longest Palindromic Substring
Write a python program to find the longest palindromic substring from a given
string. Return the substring.
Expected Output:
Original string: abcdcsdfabbccb
Longest Palindromic Substring from the said string? bccb
40. Replace Lowercase with Uppercase
Write a python program to replace each lowercase letter with the same
uppercase letter of a given string. Return the newly created string.
Sample Data:
("Python") -> "PYTHON"
("abcdcsd") -> "ABCDCSD"
41. Longest Common Subsequence Length
Write a python program to calculate the length of the longest common
subsequence of two given strings. The strings consist of alphabetical characters.
Sample Data:
("abcdkiou", "cabsdf") -> 3
("pqrjad", "qr") -> 2