Showing posts with label input handling. Show all posts
Showing posts with label input handling. Show all posts

Thursday, August 22, 2024

Character-by-Character Analysis: Identifying Vowels and Consonants in a Word

You need to create a program that analyzes a given word character by character. For each character, the program should determine whether it is a vowel or a consonant. The program should stop processing as soon as it encounters a non-alphabetic character.


1. **Input Handling**:
   - The program starts by reading a word from the user input.

2. **Processing Each Character**:
   - It then iterates through each character in the word.

3. **Character Check**:
   - For each character, the program first checks if it is an alphabetic character. If it is not, the program stops further processing.
   - If the character is alphabetic, it checks whether it is a vowel (i.e., one of the characters in the string `'aeiou'`).
   - Based on this check, it prints either "vowel" if the character is a vowel, or "consonant" if it is not.



This approach processes a word to classify each character as either a vowel or a consonant, stopping when encountering a non-alphabetic character. It provides a clear and straightforward way to analyze the types of characters in a given input.

Efficiently Tracking and Querying Word Positions in a List Using a Dictionary

You need to create a program that processes a list of words input by the user, stores the positions (indices) of each word, and then allows querying of these positions. If a user queries a word that exists in the list, the program should return all indices where that word appears. If the word does not exist in the list, it should return "not found." 

1. **Reading Input**:
   - The program starts by taking a single line of input, which consists of words separated by spaces. This line is split into a list of words.

2. **Building Index Dictionary**:
   - The program then constructs a dictionary to map each word to a list of its indices (positions) in the original list. This is achieved by iterating through the list of words and recording each word's position.

3. **Handling Queries**:
   - After building the dictionary, the program waits for another user input, which is a query for a specific word. It looks up this word in the dictionary.
   - If the word exists in the dictionary, it prints out all indices where this word appears. If the word is not found, it outputs "not found."

### Summary:

This approach allows you to efficiently track the positions of words within a list and handle user queries to retrieve these positions. It uses a dictionary to store and quickly access the positions of each word, making it effective for both storing and querying word positions.

Featured Post

How HMT Watches Lost the Time: A Deep Dive into Disruptive Innovation Blindness in Indian Manufacturing

The Rise and Fall of HMT Watches: A Story of Brand Dominance and Disruptive Innovation Blindness The Rise and Fal...

Popular Posts