Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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 the
user.

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!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote