112,244 views
7 votes
7 votes
13.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:

z
hello zoo sleep drizzle
the output is:

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

User Oliver Keyes
by
2.7k points

1 Answer

11 votes
11 votes

Answer:

Step-by-step explanation:

The required program prints words which have an occurrence of an inputted alphabet from a list of given words. The program written in python 3 goes thus :

character = input("Enter a character: ")

#prompts user of character of choice

words = input("Enter the words: ")

#prompts user to enter a list of words

split_words = words.split()

#split the words in the list given

for w in split_words:

#iterate through the splitted words

if character in w:

#if an occurence of the character exists in the word

print(w)

#print the word.

A sample run of the program is attached

User Varun Katta
by
3.0k points