Write a program that counts the number of words in a sentence entered by the use
ID: 3631773 • Letter: W
Question
Write a program that counts the number of words in a sentence entered by theuser.
I wrote a program for the question but I don't know how to fix the error in it. Please help here is my program:
# counter.py
# This program will count the number of words in a sentence given by the user
import string
def counter():
print("This program counts the number of words in a sentence")
print()
p= eval(input("Enter a sentence: "))
words= string.split(p)
wordCount= len(words)
print("The total number of words is:", wordCount)
counter()
Explanation / Answer
import string
def main():
print "This program calculates the number of words in a sentence"
print
p = raw_input("Enter a sentence: ")
words = string.split(p)
wordCount = len(words)
print ("The total word count is:", wordCount)
main()
This Program should work fine!!! Cheers!!
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.