Question

In Python, write a function numLetters() that keeps prompting the user for words until they hit...

In Python, write a function numLetters() that keeps prompting the user for words until they hit return (using while loops). The function should then return the percent of 3-letter words that were entered. So, if a user entered ten words and 4 of the words had 3 letters, then the percent of 3-letter words is 40

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def numLetters():
   wordsInput=[]   #list for storing words
   #reading words until enter return
   while(True):
       inpt=input("Enter word :")
       if(inpt!="return"):
           wordsInput.append(inpt)
       else:
           break
  
   wordsDigitCount=[] #for storing every word count
   #counting every word count
   for word in wordsInput:
       dcount=0
       for ch in word:
           if(ch.isspace()!= True):
               dcount=dcount+1
       wordsDigitCount.append(dcount)

   #calculating 3 letter word count and percentage
   threeLetter=0
   for i in range(len(wordsDigitCount)):
       if(wordsDigitCount[i]==3):
           threeLetter=threeLetter+1
   return len(wordsInput),threeLetter*10   #returning count of total words and percentage of 3 letter words
      
#main program
totalWords,percentage=numLetters() #storing function return values
print("out of {} words, 3-letter percentage : {}".format(totalWords,percentage))

  

Add a comment
Know the answer?
Add Answer to:
In Python, write a function numLetters() that keeps prompting the user for words until they hit...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Perl Write a program with a subroutine that keeps prompting for a filename until a valid...

    Perl Write a program with a subroutine that keeps prompting for a filename until a valid file is entered by the user (print out "file found, thanks") or until five attempts have failed (print out "you did not enter a valid file name"). The sub in this case does not return any value.

  • Write a Python program that keeps reading in names from the user, until the user enters...

    Write a Python program that keeps reading in names from the user, until the user enters 0. Once the user enters 0, you should print out all the information that was entered by the user. Use this case to test your program: Input: John Marcel Daisy Samantha Nelson Deborah 0 ================ Output: John Marcel Daisy 25 Samantha Nelson Deborah Hints: Create an array Names to hold the input names. Use the Names.append(x) function to add a new name to the...

  • Using Python, write a program that keeps asking the user for text until they type "exit"...

    Using Python, write a program that keeps asking the user for text until they type "exit" To Exit Or Not Write a program that keeps asking the user for text until they type "exit" Console 1 Enter number 1 3 Enter number 5 5 Enter number 7 Enter number 8 1 9 Enter number 10 9 11 Enter number 12 3 13 Enter number 14 4 15 Enter number 16 exit 17 Bye! 18

  • python Write a progran that reads values from the user until a blank line is entered....

    python Write a progran that reads values from the user until a blank line is entered. Display the total of al1 the values entered by the user (or 0.0 if the first value entered is a blank 1ine). Complete this task using recursion. program must not use any loops. Your Hint: The body of your recursive function will need to read one value from the user, and then determine whether or not to make a recursive call. Your funetion does...

  • Python Programming Q.3) Write a program that repeatedly asks the user to enter words until they...

    Python Programming Q.3) Write a program that repeatedly asks the user to enter words until they enter a period ("."). Your program should then print all of the words they entered including the period) on a single line separated by spaces. For example, Enter some words (. to stop): > hello > world hello world.

  • In python Prompt user to input the number of the month they were born. Using a...

    In python Prompt user to input the number of the month they were born. Using a while loop, continue prompting for the month until the user inputs a valid month number. Figure out the number of days in the month the user entered. Then prompt the user to input the day they were born. Using a while loop, continue prompting until they input a day that is within the range of the number of days in their month. Assume 28...

  • Write a java program that keeps asking the user to enter a number until the user...

    Write a java program that keeps asking the user to enter a number until the user quits and prints how many even and how many odd numbers entered by the user. The loop terminates if the user enters -1 (it indicates that there will be no more number entering by the user). In other words, as long as the user doesn’t enter -1, the loop will be executed. Please add comments to the program to understand/ explain the code.

  • Write a function in python ABC() that prompts for a choice of A, B, or C...

    Write a function in python ABC() that prompts for a choice of A, B, or C and uses a while loop to keep prompting until it receives the string 'A', 'B', or 'C'. The function should then return the choice.

  • Write a full python program that asks the user to type in 10 words using a...

    Write a full python program that asks the user to type in 10 words using a loop, prompting the user for each word with a number. The program then displays the longest word and the shortest word the user typed in.

  • 1. In Python, Write a function to convert inches into yards, feet and inches. The functions...

    1. In Python, Write a function to convert inches into yards, feet and inches. The functions should take one parameter, 'inches', and print out the number of yards, feet, and inches equivalent to the value of the argument. Call the function after prompting the user to enter the number of inches. Don't forget to convert the input to an 'int'. 2. In Python,Write a function to convert celsius to fahrenheit. The function should return a value, which you should assign...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT