Last active
October 11, 2017 19:30
-
-
Save bmontana/8bb0c22ce11b58510623ffee844d2cb4 to your computer and use it in GitHub Desktop.
Creates an acronym from input text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# U05_Ex04_Acronym.py | |
# | |
# Author: Bill Montana | |
# Course: Coding for OOP | |
# Section: A3 | |
# Date: 30 Oct 2017 | |
# IDE: Pythonista for iOS | |
# | |
# Assignment Info | |
# Exercise: 4 | |
# Source: Python Programming | |
# Chapter: 5 | |
# | |
# Program Description | |
# Creates an acronym from input text | |
# | |
# Algorithm (pseudocode) | |
# Print intro | |
# Get text from user | |
# Parse string to get first letter of each word | |
# Output result | |
def main(): | |
# Print intro | |
print('This program creates an acronym from input text.') | |
# Get text from user | |
inputStr = input('Please enter a text string consisting of multiple words: ') | |
# Parse string to get first letter of each word | |
words = inputStr.split(' ') | |
acronym = '' | |
for word in words: | |
acronym += word[0].upper() | |
# Output result | |
print('The acronym for...\n{0}\nis...\n{1}'.format(inputStr, acronym)) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The secret sauce in this one is in the
split()
(splitinputStr
on spaces) andupper()
(convert first letter inword
to upper case before adding toacronym
) functions.