Skip to content

Instantly share code, notes, and snippets.

@bmontana
Created October 12, 2017 02:58
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/68f696777653ef0e7420a306dc301e43 to your computer and use it in GitHub Desktop.
Save bmontana/68f696777653ef0e7420a306dc301e43 to your computer and use it in GitHub Desktop.
Counts the number of words in a sentence entered by the user
# U05_Ex09_WordCount.py
#
# Author: Bill Montana
# Course: Coding for OOP
# Section: A3
# Date: 11 Oct 2017
# IDE: PyCharm Community Edition
#
# Assignment Info
# Exercise: 9
# Source: Python Programming
# Chapter: 5
#
# Program Description
# Counts the number of words in a sentence entered by the user
#
# Algorithm (pseudocode)
# Print intro
# Get sentence from user
# Count words with len(str.split(' '))
# Print word count
def main():
# Print intro
print('This program counts the number of words in a sentence entered by the user.')
# Get sentence from user
inputStr = input('Please enter a sentence: ')
# Count words with len(str.split(' '))
wordCount = len(inputStr.split(' '))
# Print word count
print('Word count: {0}'.format(wordCount))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment