Ask Question
21 February, 07:22

7.12 LAB: Contains the character

Write a program that reads a character, then reads in a list of words. 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.

Ex: If the input is:

hello Zoo sleep drizzle

the output is:

zoo

drizzle

Keep in mind that the character 'a' is not equal to the character "A".

+5
Answers (2)
  1. 21 February, 08:03
    0
    The solution code is written in Python 3

    input_char = input ("Enter a character: ") sentence = input ("Enter a sentence: ") word_list = sentence. split (" ") for word in word_list: for c in word: if (c = = input_char) : print (word) break

    Explanation:

    Firstly, use the input function to get a input character and sentence from user (Line 1 - 2)

    Next, use the split method to divide the sentence into a list of individual words using single space as the delimiter (Line 4).

    Create an outer for loop to traverse each word in the word_list and create another inner loop to traverse each character in the word and check if there is any character match with the input character. If so print the word and terminate the inner loop and proceed to the next round of the outer loop.

    After finishing the loop, all the relevant words will be printed.
  2. 21 February, 09:24
    0
    Answer:there is Java program and C+ + program
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “7.12 LAB: Contains the character Write a program that reads a character, then reads in a list of words. The output of the program is every ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers