Created
October 12, 2017 02:58
-
-
Save bmontana/68f696777653ef0e7420a306dc301e43 to your computer and use it in GitHub Desktop.
Counts the number of words in a sentence entered by the user
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_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