The goal is to make a list from the user's paragraph and iterating so that I can count how many words contain special letters "j,x,q,z".
Example input:
In a hole in the ground, there lived a hobbit. Not a nasty, dirty, wet hole, filled with the ends of worms and an oozy smell, nor yet a dry, bare, sandy hole with nothing in it to sit down on or to eat; it was a hobbit-hole, and that means comfort.
Example output: 1 word with a rare character
I've started the code where I break the user's paragraph into a list but I'm having a hard time iterating through the list and finding each instance of the special letters.
This is what I have so far:
def rareChar(words):
rareWords = 0
rareChars = ['j', 'x', 'q', 'z']
for astring in words:
wds = words.split()
for char in wds:
if char in rareChars:
rareWords = rareWords + 1
return rareWords
def CoolPara(words):
print(rareChar(words), 'word(s) with a rare character')
# DO NOT CHANGE CODE BELOW
print(CoolPara(input("Enter: ")))
If I run with the example input, I get an output of '0 word(s) with a rare character'. How could I fix this so that I can get the expected output. Any help would be greatly appreciated as I am still relatively new to coding
Also a quick note: I am only allowed to use the methods/functions of split() and Len()