Question: Write a python script -ask the user to enter a sentence using input method and assign the sentence to a string. A sentence could be
Write a python script
-ask the user to enter a sentence using input method and assign the sentence to a string. A sentence could be anything.
- extract each word from the sentence and put it in a list. DO NOT USE SPLIT( ) to accomplish this.
- Once processed, print each word in a line of its own and at the bottom of the list state the number of letters and number of words found.
I have created the code so far - cant put each word in a new line.
code as below :-
import re
ask = input("Please enter a sentence. ") x = len(ask) # length of the sentence count = len(re.findall(r'\S+', ask)) # use \S incase you want to use decimal numbers. For input like inter-communiction word count will be 1. # use of \w gives 2 word count for inter-communication. print (re.findall(r'\S+', ask)) print("Number of letters : " + str(x)) print("Number of words : " + str(count))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
