[go: up one dir, main page]

0% found this document useful (0 votes)
4 views6 pages

Programming 5

The Python program in CS 1101 performs three operations on the name 'PraiseGod': substring extraction, vowel counting, and string reversal. It efficiently handles user input, counts vowels using a set for quick lookups, and reverses the string while preserving original casing. The program showcases Python's string manipulation capabilities with an O(n) time complexity for all operations.

Uploaded by

shumbapraise71
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)
4 views6 pages

Programming 5

The Python program in CS 1101 performs three operations on the name 'PraiseGod': substring extraction, vowel counting, and string reversal. It efficiently handles user input, counts vowels using a set for quick lookups, and reverses the string while preserving original casing. The program showcases Python's string manipulation capabilities with an O(n) time complexity for all operations.

Uploaded by

shumbapraise71
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/ 6

CS 1101 - Programming Assignment Unit 5

Course:

Programming Fundamentals (CS 1101)


NAME: PRAISEGOD SHUMBA
University: University of the People
Technical Explanation

This Python program performs three key operations on the name "PraiseGod":

1. Substring Extraction

Ÿ Input Handling: Accepts user input for n and clamps it between 0 and the name's length (9 characters)

using max(0, min(n, len(name)))

Ÿ String Slicing: Uses name[:n] to extract characters from index 0 to n-1

Ÿ Validation: Prevents index errors for values outside 0-9 range

2. Vowel Counting

Ÿ Case Handling: Converts characters to lowercase using char.lower() for uniform comparison

Ÿ Set Membership: Uses a vowel set {'a','e','i','o','u'} for O(1) lookup efficiency

Ÿ Generator Expression: Efficiently counts matches with sum() and generator

3. String Reversal
Extended Slicing: Uses [::-1] syntax to create reversed copy

Ÿ Original Preservation: Maintains original casing while reversing

Screenshot.
Key Observations:

Ÿ Substring extraction shows "PraiseGod" (9 characters)

Ÿ Vowel count identifies 4 vowels (a, i, e, o)

Ÿ Reversal maintains original casing: "PraiseGod" → "doGesiarP"

The program demonstrates Python's string manipulation capabilities with O(n) time complexity for all operations,

making it efficient for typical use cases.

Screenshot.
Reference.

Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press. This book is licensed

under Creative Commons Attribution-NonCommercial 3.0 Unported

You might also like