134k views
0 votes
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. 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.

User Bob Kimani
by
2.9k points

2 Answers

4 votes

Final answer:

The question asks for a program that reads an integer representing the number of words in a list, the words themselves, and a character, and then prints each word from the list that contains the character at least once. A sample Python script has been provided to illustrate how this can be achieved by iterating through the list and checking for the presence of the character in each word.

Step-by-step explanation:

To create a program that reads an integer, a list of words, and a character, where the integer indicates the number of words in the list, and the output displays every word containing the specified character at least once, you would typically use a programming language like Python. The task involves iterating through the list of words and checking if each word contains the character. Here is a simple example in Python:

# Read the integer
n = int(input('Enter the number of words: '))

# Read the list of words
word_list = []
for i in range(n):
word = input('Enter word #' + str(i+1) + ': ')
word_list.append(word)

# Read the character
c = input('Enter the character to search for: ')

# Output words containing the character
for word in word_list:
if c in word:
print(word)

This script prompts the user to input the number of words, the words themselves, and the character to search for. It then prints out any word that contains the character.

User Nzall
by
4.1k points
3 votes

Answer:

Following is given the code as required. All the description for code is given inside the code as comments. The output of code is also attached at end. I hope it will help you!

Step-by-step explanation:

Write a program that reads an integer, a list of words, and a character. The integer-example-1
Write a program that reads an integer, a list of words, and a character. The integer-example-2
Write a program that reads an integer, a list of words, and a character. The integer-example-3
User Suszterpatt
by
2.9k points