Easy (10 questions):
- Write a Python program to count the number of vowels in a given string.
- Convert a string to uppercase and lowercase using built-in string methods.
- Write a Python program to check if a string is a palindrome.
- Extract the first 5 characters from a given string.
- Write a Python program to reverse a string.
- Find the length of a given string using a built-in function.
- Write a Python program to replace all occurrences of a specific character in a string with another character.
- Write a Python program to split a string into a list of words.
- Write a Python program to concatenate two strings.
- Write a Python program to count how many times a specific substring occurs in a given string.
Medium (6 questions):
Write a Python program to count the occurrences of each character in a string.
- Sample Input:
"apple"
- Sample Output:
{'a': 1, 'p': 2, 'l': 1, 'e': 1}
- Sample Input:
Given a string, write a Python program to remove all spaces and capitalize the first letter of each word.
- Sample Input:
"hello world python"
- Sample Output:
"HelloWorldPython"
- Sample Input:
Write a Python program to find the longest word in a sentence.
- Sample Input:
"Python is fun and educational"
- Sample Output:
"educational"
- Sample Input:
Write a Python program to check if a given string is a valid email address (use basic rules like containing "@" and ".").
Write a Python program to swap the case of all characters in a string (lowercase to uppercase and vice versa).
Given two strings, write a program to find all the characters they have in common.
- Sample Input:
"abcde"
,"cdefg"
- Sample Output:
['c', 'd', 'e']
- Sample Input:
Hard (4 questions):
Write a Python program to find the first non-repeating character in a string.
- Sample Input:
"swiss"
- Sample Output:
"w"
- Sample Input:
Write a Python program to find all possible permutations of a string.
- Sample Input:
"abc"
- Sample Output:
["abc", "acb", "bac", "bca", "cab", "cba"]
- Sample Input:
Given a string containing numbers and letters, write a program to sum all the digits in the string.
- Sample Input:
"ab123cd45"
- Sample Output:
15
- Sample Input:
Write a Python program to check if two strings are anagrams of each other (contain the same characters in different order).
- Sample Input:
"listen"
,"silent"
- Sample Output:
True
- Sample Input: