0% found this document useful (0 votes)
10 views8 pages

Python String Coding Challenges

The document contains a series of Python coding questions focused on string manipulation and analysis. Each question provides a specific task, such as reversing strings, counting vowels, checking for palindromes, and more, along with example test cases for clarity. The tasks aim to enhance programming skills related to string handling in Python.

Uploaded by

temporary.id0409
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views8 pages

Python String Coding Challenges

The document contains a series of Python coding questions focused on string manipulation and analysis. Each question provides a specific task, such as reversing strings, counting vowels, checking for palindromes, and more, along with example test cases for clarity. The tasks aim to enhance programming skills related to string handling in Python.

Uploaded by

temporary.id0409
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python String Coding Questions

1. The Spy’s Hidden Message

A secret agent from the Intelligence Bureau receives encrypted messages that are
written backward to hide their content.
To read them, you need to reverse the string and return the decoded message.

Example Test Cases:

Input: "nohtyP" → Output: "Python"


Input: "egassem" → Output: "message"
Input: "IA" → Output: "AI"
Input: "gnimmargorP" → Output: "Programming"
Input: "esrever" → Output: "reverse"

2. Song Analyzer – Count the Melody

A music app wants to analyze lyrics to measure how "melodic" they are by counting
vowels (a, e, i, o, u).
Your job is to return how many vowels appear in the given lyric line.

Example Test Cases:

Input: "Hello World" → Output: 3


Input: "Education Rocks" → Output: 6
Input: "Sky" → Output: 0
Input: "AI Tools" → Output: 4
Input: "Beautiful Day" → Output: 6

3. The Mirror Username

An online game wants usernames that read the same both ways for a “Mirror
Challenge”.
You must check if a given username is a palindrome. Return True or False.
Example Test Cases:

Input: "madam" → Output: True


Input: "level" → Output: True
Input: "python" → Output: False
Input: "noon" → Output: True
Input: "data" → Output: False

4. Password Inspector

A cybersecurity app validates passwords.


The rule: Passwords must contain at least one uppercase and one lowercase letter.
Print "Strong" if it meets the criteria, otherwise "Weak".

Example Test Cases:

Input: "Python3" → Output: Strong


Input: "HELLO" → Output: Weak
Input: "world" → Output: Weak
Input: "PyThOn" → Output: Strong
Input: "code123" → Output: Weak

5. Clean My Notes

A note-taking app wants to remove all spaces from user notes to save memory.
Write a program that removes all spaces from the given sentence.

Example Test Cases:

Input: "Python is fun" → Output: "Pythonisfun"


Input: " Hello " → Output: "Hello"
Input: "a b c" → Output: "abc"
Input: "Open AI" → Output: "OpenAI"
Input: " No Space " → Output: "NoSpace"

6. Character Frequency in Chat

A social app analyzes the frequency of each character in a message to detect spam
patterns.
Return a dictionary showing each character and its count.

Example Test Cases:

Input: "banana" → Output: {'b':1, 'a':3, 'n':2}


Input: "aabbcc" → Output: {'a':2, 'b':2, 'c':2}
Input: "hello" → Output: {'h':1, 'e':1, 'l':2, 'o':1}
Input: "Python" → Output: {'P':1, 'y':1, 't':1, 'h':1, 'o':1,
'n':1}
Input: "aaaa" → Output: {'a':4}

7. Extract the Email Domain

A college automation system needs to extract the domain name (after '@') from each
student’s email ID.

Example Test Cases:

Input: "user@[Link]" → Output: "[Link]"


Input: "student@[Link]" → Output: "[Link]"
Input: "info@[Link]" → Output: "[Link]"
Input: "abc@[Link]" → Output: "[Link]"
Input: "team@[Link]" → Output: "[Link]"

8. Message Flipper

A chat app creates “mock” versions of messages by swapping case (uppercase →


lowercase, lowercase → uppercase).

Example Test Cases:

Input: "Python" → Output: "pYTHON"


Input: "HELLO" → Output: "hello"
Input: "hello123" → Output: "HELLO123"
Input: "PyThOn" → Output: "pYtHoN"
Input: "Data" → Output: "dATA"
9. Auto Word Replacement

An AI writing tool replaces certain keywords with better suggestions.


Write a program that replaces a given word with a new one in a sentence.

Example Test Cases:

Input: "I like Java", "Java", "Python" → Output: "I like Python"
Input: "Hello world", "world", "AI" → Output: "Hello AI"
Input: "Data Science", "Data", "ML" → Output: "ML Science"
Input: "Old car", "car", "bike" → Output: "Old bike"
Input: "Smart watch", "watch", "phone" → Output: "Smart phone"

10. Word Twins (Anagram Check)

A puzzle app asks players to check if two given words contain the same characters in
different orders — i.e., anagrams.

Example Test Cases:

Input: "listen", "silent" → Output: True


Input: "earth", "heart" → Output: True
Input: "python", "typhon" → Output: True
Input: "hello", "world" → Output: False
Input: "data", "tada" → Output: True

11. Headline Word Counter

A blogging platform shows how many words are in an article headline.

Example Test Cases:

Input: "Python is fun" → Output: 3


Input: "AI is the future" → Output: 4
Input: "Hello" → Output: 1
Input: "ChatGPT from OpenAI" → Output: 3
Input: "Data Science Rocks" → Output: 3
12. Longest Word Finder

A dictionary app highlights the longest word in a sentence to suggest vocabulary


improvements.

Example Test Cases:

Input: "Python is amazing" → Output: "amazing"


Input: "AI is fast" → Output: "fast"
Input: "OpenAI creates ChatGPT" → Output: "ChatGPT"
Input: "Data Science" → Output: "Science"
Input: "I love coding" → Output: "coding"

13. Text Cleaner – Remove Punctuation

A text cleaning app removes punctuation marks before performing NLP analysis.

Example Test Cases:

Input: "Hello, world!" → Output: "Hello world"


Input: "Python@3.10" → Output: "Python310"
Input: "It's fun!" → Output: "Its fun"
Input: "Hi...there??" → Output: "Hithere"
Input: "Good-day!" → Output: "Goodday"

14. Count Numbers in Username

An online portal ensures that usernames don’t contain too many digits.
Write a program to count digits in a given string.

Example Test Cases:

Input: "abc123" → Output: 3


Input: "hello" → Output: 0
Input: "2025year" → Output: 4
Input: "AI12345" → Output: 5
Input: "x9y8z7" → Output: 3
15. Unique Character Detector

A detective agency encrypts names by selecting the first non-repeating character from
each.
Find the first character that doesn’t repeat.

Example Test Cases:

Input: "aabbccde" → Output: "d"


Input: "racecars" → Output: "e"
Input: "python" → Output: "p"
Input: "aabb" → Output: None
Input: "swiss" → Output: "w"

16. Remove Repeated Letters

A data-cleaning system removes duplicate letters from text but keeps the first
occurrence.

Example Test Cases:

Input: "programming" → Output: "progamin"


Input: "aabbcc" → Output: "abc"
Input: "hello" → Output: "helo"
Input: "banana" → Output: "ban"
Input: "mississippi" → Output: "misp"

17. Title Formatter

A book publisher’s automation tool converts book titles so each word starts with a
capital letter.

Example Test Cases:

Input: "python is fun" → Output: "Python Is Fun"


Input: "hello world" → Output: "Hello World"
Input: "data science" → Output: "Data Science"
Input: "learn python" → Output: "Learn Python"
Input: "chatgpt rocks" → Output: "Chatgpt Rocks"

18. Login Checker (Ignore Case)

A login system verifies usernames without case sensitivity (e.g., "Admin" = "admin").

Example Test Cases:

Input: "Admin", "admin" → Output: True


Input: "Python", "PYTHON" → Output: True
Input: "User", "user1" → Output: False
Input: "AI", "ai" → Output: True
Input: "Hello", "HELLo" → Output: True

19. Word Game – Common Letters

You are creating a word game that rewards players for finding common letters between
two words.

Example Test Cases:

Input: "python", "typhoon" → Output: {'p', 'h', 'o', 'n', 't',


'y'}
Input: "apple", "grape" → Output: {'a', 'p', 'e'}
Input: "hello", "world" → Output: {'l', 'o'}
Input: "abc", "xyz" → Output: set()
Input: "data", "tada" → Output: {'a', 'd', 't'}

20. Hide Sensitive Numbers

A privacy filter replaces all digits in a message with ‘*’ to hide sensitive data.

Example Test Cases:

Input: "My pin is 1234" → Output: "My pin is ****"


Input: "Pass2025" → Output: "Pass****"
Input: "abc123xyz" → Output: "abc***xyz"
Input: "NoDigits" → Output: "NoDigits"
Input: "9Lives" → Output: "*Lives"

Common questions

Powered by AI

The 'Auto Word Replacement' feature enhances AI writing tools by automatically substituting words with more suitable alternatives to improve clarity, precision, and style. For example, replacing 'Java' with 'Python' in 'I like Java' results in 'I like Python'. This functionality aids in maintaining consistency and relevance in writing outputs, adapting the text to specific contexts or preferences, thereby streamlining the editing process and ensuring the content aligns with desired nomenclature or terminology .

The 'Character Frequency in Chat' feature aids in spam detection by analyzing the frequency of characters in messages. High repetition of specific characters or strings can be indicative of automated spamming tools. By monitoring these frequencies, social apps can identify unusual patterns that deviate from normal user behavior, such as messages with excessive repetition of certain characters like 'a' in 'aaaa'. This analysis allows for the early detection and prevention of spam, thereby protecting users from potentially malicious activities .

Identifying the 'Longest Word' in a sentence can facilitate vocabulary development by encouraging users to engage with more complex and varied language. Highlighting words like 'amazing' in 'Python is amazing' draws attention to potentially unfamiliar or underutilized vocabulary within context, prompting users to explore definitions and usage. This approach supports learning by integrating vocabulary expansion into everyday reading, increasing language proficiency through exposure to and adoption of diverse lexicons .

The 'Unique Character Detector' is crucial for encryption methods used by detective agencies because it identifies the first non-repeating character in a string, which can serve as a simplified representation or key in cryptographic systems. This feature reduces data redundancy and ensures that the encrypted message has a unique component, making it more secure. A unique character like 'd' in 'aabbccde' provides a reliable point of reference for encoding sensitive information .

Using the 'Title Formatter' in automated book publishing can lead to challenges such as misinterpretation of proper nouns or stylized text exceptions. Automating title capitalization to convert book titles like 'python is fun' to 'Python Is Fun' may incorrectly capitalize articles, prepositions, or intentionally stylized names. Ensuring proper context-based capitalization while preserving specific formatting intentions requires nuanced algorithms capable of recognizing grammatical rules, posing significant complexities in implementation and maintaining consistency across diverse datasets .

The 'Mirror Username' feature ensures uniqueness by requiring that usernames be palindromes—words or phrases that read the same backward as forward. This constraint limits potential usernames to those that are inherently symmetrical, thus reducing the pool of available combinations and ensuring that each valid username maintains a visual and structural uniqueness. For example, names like 'madam' and 'level' are palindromes, while 'python' is not .

In the 'Song Analyzer' feature, vowels (a, e, i, o, u) are used as an indicator of how 'melodic' a line of lyrics is. By counting the number of vowels, the feature quantifies the potential for smooth and sonorous qualities in the lyrics. This method leverages the natural musicality and fluidity of vowel sounds to provide an objective measure of a song's lyrical melody. For instance, the phrase 'Education Rocks' contains six vowels, indicating a potentially melodic structure .

Optimizing the 'Hide Sensitive Numbers' feature could involve implementing context-aware algorithms that not only replace numbers with asterisks but also identify surrounding patterns indicative of sensitive data, such as common password formats or account IDs. Incorporating machine learning models to recognize and generalize from examples of sensitive information could enhance detection accuracy. Additionally, user customization options for different types of numerical data could increase versatility, allowing users to specify which numeric patterns to obscure, thereby refining privacy controls .

The 'Password Inspector' feature helps improve cybersecurity by ensuring passwords contain both uppercase and lowercase letters, which increases their complexity and resilience against brute force attacks. This requirement diversifies the possible character combinations within a password, thereby enhancing its strength and making unauthorized access more difficult. For instance, 'Python3' is deemed 'Strong' due to its mixed case, whereas 'HELLO' is considered 'Weak' .

The 'Extract the Email Domain' function benefits college automation systems by streamlining domain-specific processes. For example, by extracting 'school.edu' from a student's email 'student@school.edu', the system can route communications or apply policies according to the institution's domain. This feature simplifies tasks like categorizing student information based on institutional affiliation or directing emails to appropriate channels, thereby enhancing operational efficiency and accuracy .

You might also like