My function needs one argument words, but i want the program not to crash if no argument.
def get_count(words):
try:
consonants_str = "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ"
vowels_str = "aeiouAEIOU"
consonants_ls = []
vowels_ls = []
words_ls = []
result = {"vowels": 0, "consonants": 0}`
for element in consonants_str:
consonants_ls.append(element)
for element in vowels_str:
vowels_ls.append(element)
if type(words) != type(None):
for element in words:
words_ls.append(element)
for element in words_ls:
if element in vowels_ls:
result["vowels"] += 1
if element in consonants_ls:
result["consonants"] += 1
else:
continue
else:
result["vowels"] = 0
result["consonants"] = 0
except TypeError:
result["vowels"] = 0
result["consonants"] = 0
answer = {"vowels": result["vowels"],"consonants": result["consonants"]}
return answer`
So if I execute the function with
print(get_count())
I want, that the program doesn't show me an error like the one in the heading. The exception for that should be in the def of get_count because it should be a closed file. I don't execute in the same file, so the Exception should be independent from other files.
I hope you understand what I mean...
Thanks for your answers! NoAbL