0% found this document useful (0 votes)
8 views

CS1101 Learning Journal W5

week 5 learning journal

Uploaded by

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

CS1101 Learning Journal W5

week 5 learning journal

Uploaded by

brittisaacs19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Write program to display your name and perform following operations on it:

1. Display n characters from left. (Accept n as input from the user)

2. Count the number of vowels.

3. Reverse it.

Program:

#My name and display ‘n’ character from left

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

the substring containing the first ‘n’ characters.


#Counts the number of vowels in ‘name’

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.

#Display ‘name’ in reverse

Finally, this part of the code reverses the string ‘name’ using slicing ([::-1]) (Downey, 2015, p. 80) and

then prints the reversed string.

References: Author, A. D.,(2015). Think Python

How to Think Like a Computer Scientist (2nd ed.) Allen Downey.

https://greenteapress.com/thinkpython2/thinkpython2.pdf

You might also like