Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Quizzma Latest Articles

8.3.6 Owls CodeHS Answers

The most common answer is:

this function should return the number of words that contain “owl”!
text =”I really like owls. Did you know that an owl’s eyes are more than twice as big as the eyes of other birds of comparable weight? And that when an owl partially closes its eyes during the day, it is just blocking out light? Sometimes I wish I could be an owl.”
word =”owl”
def owl_count(text):
text=text.lower()
owlist=list(text.split())
count=text.count(word)
return count
print (owl_count(text))


The owl_count function is intended to count the number of words containing “owl” in a given text.

However, using text.count(word) directly on the entire text counts all occurrences of “owl”, including those within the same word (e.g., “owls” would count as one, but if “owl” appeared twice in the same word, it would count twice) and might not accurately reflect the number of words containing “owl.”

To count the number of words containing “owl”, you should iterate through each word in owlist and check if “owl” is a substring of that word.

Here’s a revised version of the function that does this:

text = "I really like owls. Did you know that an owl’s eyes are more than twice as big as the eyes of other birds of comparable weight? And that when an owl partially closes its eyes during the day, it is just blocking out light? Sometimes I wish I could be an owl."

word = "owl"

def owl_count(text):
    text = text.lower()
    words = text.split()  # Split the text into a list of words
    count = 0
    for w in words:
        if word in w:
            count += 1
    return count

print(owl_count(text))

This function converts the entire text to lowercase to ensure the search is case-insensitive, then splits text into a list of words. It iterates over this list, incrementing count each time a word contains the substring “owl”. Finally, it returns the total count.

This method ensures each word containing “owl” is counted accurately, regardless of its position within the word or repetition within the same word.

Was this helpful?




Quizzma Team

Quizzma Team

The Quizzma Team is a collective of experienced educators, subject matter experts, and content developers dedicated to providing accurate and high-quality educational resources. With a diverse range of expertise across various subjects, the team collaboratively reviews, creates, and publishes content to aid in learning and self-assessment.
Each piece of content undergoes a rigorous review process to ensure accuracy, relevance, and clarity. The Quizzma Team is committed to fostering a conducive learning environment for individuals and continually strives to provide reliable and valuable educational resources on a wide array of topics. Through collaborative effort and a shared passion for education, the Quizzma Team aims to contribute positively to the broader learning community.

Related Posts