Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in python code, please help Exercise 4 The goal of this program is to do some statistics on words, with a simple function. a) Start
in python code, please help
Exercise 4 The goal of this program is to do some statistics on words, with a simple function. a) Start by writing a stcingstats function with an argument num which corresponds to the number of words that the function will run on. For now the function will simply require the user to enter num words. It does not return anything at this stage. Call it from the main program with some user input. See sample run: Enter the number of words: 3 Enter a wacdit Enter a wocditpoe. Enter a wecdiecegrapodag b) Add input validation in the main program on the number of words required by the user. The number of words should be a positive integerl See below sample run: Enter the number of words: 1.5 Number of words should be a positive integerl Enter the number of words: 2 Number of words should be a positive integer! Enter the number of words: 0 Number of words should be a positive integerl Enter the number of words: 2 Enter a wecdibake Enter a bacdius c) In the function, modify the request for words to include the position of the word required. Check also that the user is entering single words (no digits, no special characters, no spaces...). Hint: You can use the method isalebal). See below sample run: Enter the number of words: 3 Enter word 1:I love programing Please enter a single word consisting of letters onlyl Enter word 2:11:I Please enter a single word consisting of letters only! Enter word 2:love Enter word 3ipropgeamming d) In addition to all the above, your function should now return the length of the longest word entered. There are no words with length less than 0 See below sample run: Enter the number of words: 3 Enter word 1:I Enter word 2:Inve Enter word 3:programming The length of the longest word entered was: 11 letters. e) In addition to all the above, your function should now return the length of the shortest word entered. There is no maximum length for words! See below sample run: Enter the number of words: 3 Enter word 1:I. Enter word 2ilove Enter word 3:programming The length of the longest word entered was: 11 letters. The length of the shortest word entered was: 1 letters. f) In addition to the above, the function should now also return the first and last word according to lexicographic order (the order in the dictionary). See below sample run: Enter the number of words: 7 Enter word 1:T Enter word 3isuffer Enter word 4ibut Enter word 6:do5T Enter word Zilearn The length of the longest word entered was: 6 letters. The length of the shortest word entered was: 1 letters. According to lexicographic order, the first word entered was: I According to lexicographic order, the last word entered was: suffer Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started