Skip to content

Instantly share code, notes, and snippets.

@bmontana
Last active October 11, 2017 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmontana/8bb0c22ce11b58510623ffee844d2cb4 to your computer and use it in GitHub Desktop.
Save bmontana/8bb0c22ce11b58510623ffee844d2cb4 to your computer and use it in GitHub Desktop.
Creates an acronym from input text
# 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()
@bmontana
Copy link
Author

The secret sauce in this one is in the split() (split inputStr on spaces) and upper() (convert first letter in word to upper case before adding to acronym) functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment