Write a program that reads an integer, a list of words, and a character
Added by William M.
Step 1
Sure! Let's break down the task of writing a program that reads an integer, a list of words, and a character step by step. Show more…
Show all steps
Your feedback will help us improve your experience
James Kiss and 57 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Write a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. For coding simplicity, follow each output word by a comma, even the last one. Assume at least one word in the list will contain the given character. Assume that the list of words will always contain fewer than 20 words.
James K.
(Game: hangman) Write a hangman game that randomly generates a word and prompts the user to guess one letter at a time, as shown in the sample run. Each letter in the word is displayed as an asterisk. When the user makes a correct guess, the actual letter is then displayed. When the user finishes a word, display the number of misses and ask the user whether to continue playing. Create a list to store the words, as follows: # Use any words you wish words $=[" \text { write" }, \text { "that", "program", } \dots]$ (Guess) Enter a Tetter in word $* * * * * *>p$ (Guess) Enter a Tetter in word pre*rrow $>p$ $p$ is already in the word (Guess) Enter a letter in word pre*rrin $>0$ (Guess) Enter a letter in word pro*r** > g (Guess) Enter a letter in word progr** > n $\mathrm{n}$ is not in the word (Guess) Enter a letter in word progr** > $\mathrm{m}$ (Guess) Enter a letter in word progr*m $>a$ The word is program. You missed 1 time Do you want to guess another word? Enter y or $n>$
Write a program that asks the user for the name of a file. The program should read the file using the filename from step 1, assuming that each line in the file contains one word. Store each word as an element in the list, so that one list has all of the words in the file. Iterate over each item in the list using a loop, looking at the length of each word to do the following: Calculate and print the shortest word (word with the fewest letters). Calculate and print the longest word (word with the most letters). Print the average length of all words (see "Tips" below). In addition to printing the output for steps 5-7, also write this same data to a file called: word_result.txt The sample input/output below assumes a file called words.txt with these numbers (although your code must work with any filename containing any words): Mary had a little lamb Sample input/output: Enter the name of the file: words.txt Shortest word: a Longest word: little Average word length: 3.60 (The same results printed above are also stored in the file called word_result.txt)
Akash M.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD