Python Strings Practice

"The difference between the almost-right word & the right word is really a large matter—it’s the difference between the lightning bug and the lightning."

— Mark Twain

Easy

  1. Write a program that asks the user to input their name and then prints a welcome message using their name. Example: Welcome, John!
  2. Write a Python program that asks the user for their favorite color and prints how many letters the color has. Example: Your favorite color has 4 letters.
  3. Write a program that takes a word from the user and prints the first and last letter of the word. Example: For the word "apple," the output should be: First letter: a, Last letter: e
  4. Write a program to input a name and then print the number of letters in that name.
  5. Write a program to input a word and then print the first 3 and the last 2 characters of that word. In case the word input is less than 3 letters, return the input word itself.
  6. Write a program to input a sentence and then print the characters present at the odd index only.
  7. Ask the user to enter their favorite fruit, then print the fruit in all uppercase letters. Example: MANGO
  8. Write a Python program to ask the user for two words and join them together with a space in between. Example: hello world
  9. Ask the user for a word and then print that word repeated 3 times on the same line. Example: If the input is "fun," the output will be: funfunfun
  10. Write a program to input a word and then print the the first half of that word.
  11. Write a Python program that asks the user to input a word and checks if the letter 'a' is in the word. If it is, print 'a' is in the word!
  12. Ask the user to input a word, then print the word backward. Example: For the input "python," the output will be: nohtyp
  13. Moderate

  14. Write a Python function to check if a given string is a palindrome (reads the same forwards and backwards).
  15. Write a Python program to count how many vowels are present in a given string.
  16. Please enter a 10-digit phone number to verify if it's a valid Indian phone number. A valid Indian phone number starts with 6, 7, 8, or 9 and is exactly 10 digits long (e.g., 9876543210, 9123456789 )
  17. Write a Python program to find the length of a string without using the built-in len() function.
  18. Write a Python function that takes a string as input, removes all spaces from the string, and returns the resulting string.
  19. Write a program that reads a number from the user and remove all zeroes from it and display the new number.
  20. Write a Python function to check if a given string contains only digits.
  21. Write a Python function to check if a given string contains only digits.(Note: Please dont use any inbuilt String function in this question)
  22. Write a program to ask the user for their full name and then print only their initials. Example: For "John Doe," the output should be: J.D.
  23. Write a Python program to replace all occurrences of a specific character in a string with another character.
  24. Write a Python program to capitalize the first letter of each word in a given string.
  25. Write a Python function that concatenates two strings without using the + operator.
  26. Write a Python program to check if a string starts with a given substring.
  27. Write a Python function that counts the number of uppercase and lowercase characters in a string.
  28. Write a Python program to find all occurrences of a substring in a given string.
  29. Write a program to accept and change the case of each letter of the string. Display the new string.
  30. Write a program that accepts a word and checks if it is Palindrome or just a special word.
    Hint A Palindrome is a word which reads that same backwards as forward. For Example: MADAM,MALAYALAM,CIVIC etc .
    Special Words are those which start and end with the same character. For example, COMIC, WINDOW ,etc .
  31. Write a Python function that counts the number of words in a given sentence.


  32. Advanced

  33. Write a program to accept a word and convert into lowercase if it is in uppercase, and display the new word by replacing only the vowels with the character following it.
  34. Write a Python program that takes a phone number as input from the user, masks all digits except the first two and last two, and then prints the masked phone number.
  35. Write a Python program to input a word and print the new word formed by arranging each letter lexicographically (alphabetical order).
  36. Write a Python program to find the character that appears most frequently in a string.
  37. Write a Python program to input a sentence from the user and print the first word of that word
  38. Write a Python function that removes all duplicate characters from a string and returns the result.
  39. Write a Python function that takes two strings as input and checks if one string is a substring of the other.
  40. Write a Python function to reverse each word in a given sentence, while keeping the words in the same order.
  41. Write a Python program to remove all non-alphabetic characters from a string.
  42. Write a program that reads several lines of text and prints a table indicating the number of occurrences of each letter of the alphabet in the text.
  43. For example, the phrase To be, or not to be: that is the question: contains one “a,” two “b’s,” no “c’s,” and so on.
  44. Write a Python function to split a string by spaces and return a list of words.
  45. Write a Python program to input a sentence from the user and print the last word of that word
  46. Write a Python program to convert a string to a list of characters and print it.
  47. Write a program that reads a series of strings and prints only those that end with the letters "ed"
  48. Write a program that reads a date in the format 07/21/2003 and prints it in the format July 21, 2003.
  49. Dates are commonly printed in several different formats in business correspondence. Two of the more common formats are 07/21/2003 and July 21, 2003.

Find it difficult?

Don’t lose heart, don’t be under confident, just be consistent in your preparation and be sure of everything you’ve studied. You can request a class so that we can help you understant this topic.

Feel Confident?

Your first step in learning any new topic is to be aware of your strengths and weaknesses. Once you know this, your self-preparation can be meaningful and result-oriented. Attempt an quiz to get tested.