EXTRA QUESTIONS-STRINGS
1. Write a program to create a new string made of an input string’s first, middle, and last
character.
Given:
str1 = "James"
Expected Output:
Jms
2. Write a program to create a new string made of the middle three characters of an input
string.
Given:
Case 1
str1 = "JhonDipPeta"
Output
Dip
Case 2
str2 = "JaSonAy"
Output
Son
3. Given two strings, s1 and s2. Write a program to create a new string s3 by
appending s2 in the middle of s1.
Given:
s1 = "Ault"
s2 = "Kelly"
Expected Output:
AuKellylt
4. Given two strings, s1 and s2, write a program to return a new string made of s1 and s2’s
first, middle, and last characters.
Given:
s1 = "America"
s2 = "Japan"
Expected Output:
AJrpan
5. Given string contains a combination of the lower and upper case letters. Write a
program to arrange the characters of a string so that all lowercase letters should come
first.
Given:
str1 = PyNaTive
Expected Output:
yaivePNT
6. Count all letters, digits, and special symbols from a given string
Given:
str1 = "P@#yn26at^&i5ve"
Expected Outcome:
Total counts of chars, digits, and symbols
Chars = 8
Digits = 3
Symbol = 4
7. Given two strings, s1 and s2. Write a program to create a new string s3 made of the
first char of s1, then the last char of s2, Next, the second char of s1 and second last char
of s2, and so on. Any leftover chars go at the end of the result.
Given:
s1 = "Abc"
s2 = "Xyz"
Expected Output:
AzbycX
8. Write a program to check if two strings are balanced. For example, strings s1 and s2 are
balanced if all the characters in the s1 are present in s2. The character’s position doesn’t
matter.
Given:
Case 1:
s1 = "Yn"
s2 = "PYnative"
Expected Output:
True
Case 2:
s1 = "Ynf"
s2 = "PYnative"
Expected Output:
False
9. Write a program to find all occurrences of “USA” in a given string ignoring the case.
Given:
str1 = "Welcome to USA. usa awesome, isn't it?"
Expected Outcome:
The USA count is: 2
10. Given a string s1, write a program to return the sum and average of the digits that
appear in the string, ignoring all other characters.
Given:
str1 = "PYnative29@#8496"
Expected Outcome:
Sum is: 38 Average is 6.333333333333333
11. Write a program to find the last position of a substring “Emma” in a given string.
Given:
str1 = "Emma is a data scientist who knows Python. Emma works at google."
Expected Output:
Last occurrence of Emma starts at index 43
12. Write a program to split a given string on hyphens and display each substring.
Given:
str1 = Emma-is-a-data-scientist
Expected Output:
Displaying each substring
Emma
is
a
data
scientist
13. Remove empty strings from a list of strings
Given:
str_list = ["Emma", "Jon", "", "Kelly", None, "Eric", ""]
Expected Output:
Original list of sting
['Emma', 'Jon', '', 'Kelly', None, 'Eric', '']
After removing empty strings
['Emma', 'Jon', 'Kelly', 'Eric']
14. Remove special symbols / punctuation from a string
Given:
str1 = "/*Jon is @developer & musician"
Expected Output:
"Jon is developer musician"
15. Removal all characters from a string except integers
Given:
str1 = 'I am 25 years and 10 months old'
Expected Output:
2510
16. Write a program to find words with both alphabets and numbers from an input string.
Given:
str1 = "Emma25 is Data scientist50 and AI Expert"
Expected Output:
Emma25
scientist50