Vowel Assignment
Vowel Assignment
Output:
This program starts by defining the name "Hassan Azeez" and displaying it. Then, it prompts
the user to enter the number of characters to display from the left. The program uses Python's
string slicing feature (`name[:n]`) to extract and display the specified number of characters.
Next, the program defines a function `count_vowels(s)` to count the number of vowels in a
given string `s`. This function iterates over each character in the string, checks if the character
is a vowel (by converting it to lowercase and checking if it's in the string 'aeiou'), and
increments a counter if it is. Finally, the function returns the total count of vowels.
The program then calls this function with the name as the argument, stores the result in the
variable `vowels_count`, and displays this count.
Finally, the program reverses the name using Python's string slicing feature (`name[::-1]`) and
displays the reversed name.
Sources:
- "Think Python: How to Think Like a Computer Scientist" by Allen B. Downey (Chapters 7-
8)
- Python documentation (https://www.python.org/doc/)