CS1101 Learning Journal W5
CS1101 Learning Journal W5
3. Reverse it.
Program:
This part of the code takes the user's input for the variable ‘n’ and then displays the first ‘n’ characters
from the left of the string name. The slicing notation name[:n] (Downey, 2015, p. 73–74) is used to get
This section counts the number of vowels in the string name. It uses the sum function to count the
characters in 'name' that are vowels (case-insensitive). char.lower() is used to convert each character to
lowercase before checking if it is a vowel. This ensures that both uppercase and lowercase vowels are
counted.
Finally, this part of the code reverses the string ‘name’ using slicing ([::-1]) (Downey, 2015, p. 80) and
https://greenteapress.com/thinkpython2/thinkpython2.pdf