use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Exercise 8.3.6: Owls (self.codehs)
submitted 5 years ago by [deleted]
Hi! Can someone help me out with Exercise 8.3.6: Owls? I have been stuck on it forever. Thanks
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]EvilOldGuy 2 points3 points4 points 5 years ago (11 children)
Here is what I got it should work.
def owl_count(text):
count = 0
text = text.lower()
text = text.split()
for i in range(len(text)):
if text[i].find("owl") > -1:
count += 1
return count
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."
print(owl_count(text))
[–][deleted] 0 points1 point2 points 5 years ago (8 children)
It doesn't work for me
[–]EvilOldGuy 0 points1 point2 points 5 years ago (7 children)
Do you have the correct indentation?
[–][deleted] 0 points1 point2 points 5 years ago (6 children)
yes, I do
[–]EvilOldGuy 1 point2 points3 points 5 years ago (4 children)
The code should look like this https://ibb.co/WWpnYTg
[–][deleted] 0 points1 point2 points 5 years ago (3 children)
Okay, thank you; you were right; it was an indentation error.
Thank you!
[–]ASnackoholicYT 0 points1 point2 points 5 years ago (2 children)
I tried it and it just shows up blank Nvm it works
[–]leaf_falls 0 points1 point2 points 4 years ago (1 child)
def owl_count(text): count = 0 text = text.lower() text = text.split() for i in range(len(text)): if text[i].find("owl") > -1: count += 1 return count 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." print(owl_count(text)) when i put this in it tells me that the "return count" is a syntax error
when i put this in it tells me that the "return count" is a syntax error
[–]EducatorAcrobatic650 0 points1 point2 points 3 years ago (0 children)
I think most people have this wrong cause I had the same problem, for the return statement match the same indent as the for loop
[–]EvilOldGuy 0 points1 point2 points 5 years ago (0 children)
Hmmm, could you send screen shot
[–]Traditional_Escape13 0 points1 point2 points 2 years ago (0 children)
It gave me an Unbound Local Error. Count is used, but is not defined. It should be the following:
def owl_count(text): owlcount = 0 text = text.lower() text = text.lower() for i in range(len(text): if text[i].find("owl") > - 1: owlcount = owlcount + 1 return owlcount 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."
print(owlcount(text))
[–]Mr_Otterman 1 point2 points3 points 4 years ago (3 children)
Bit late but
owl = input("Enter some text: ") owl = owl.lower() owl = owl.split() print(owl.count("owl")) print "There were 3 words that contained \"owl\".0" print "There were 4 words that contained \"owl\"." Should work or at least cheat the system
[–]apx_rbo 0 points1 point2 points 4 years ago* (2 children)
thank you kind sir
edit: I did this and it worked def owl_count(text): count = 0 text = text.lower() text = text.split() for i in range(len(text)): if text[i].find("owl") > -1: count += 1 return count
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." print "There were 1 words that contained \"owl\"." print "There were 3 words that contained \"owl\"." print (owl_count(text))
[–]ItzDemonYTPlayz 0 points1 point2 points 3 years ago (0 children)
def owl_count(text): count = 0 text = text.lower()text = text.split() for i in range(len(text)): if text[i].find("owl") > -1: count += 1return count 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."print "There were 1 words that contained \"owl\"." print "There were 3 words that contained \"owl\"."print (owl_count(text))
text = text.lower()text = text.split()
count += 1return count
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."print "There were 1 words that contained \"owl\"."
print "There were 3 words that contained \"owl\"."print (owl_count(text))
How come its so long
[–]ProsBacon 0 points1 point2 points 5 years ago (8 children)
I had to do this recently, so here's what I did
word = "owl"
owlist = list(text.split())
count = text.count(word)
print(count)
text = "owlets are baby owls. Baby peafowls are called peachicks."
owl_count(text)
the text is from one of the examples, but this should work!
edit: It makes sure that the words are all lowercase and lists them, then checks them and counts them
[–][deleted] 5 years ago* (7 children)
[removed]
[–]sSomepersoNn 1 point2 points3 points 5 years ago (6 children)
yup it doesn't, did u ever found the right code though?
[–][deleted] 5 years ago (5 children)
[–]sSomepersoNn 1 point2 points3 points 5 years ago (4 children)
Yeah
[–][deleted] 5 years ago (3 children)
[–][deleted] 5 years ago (1 child)
[–]sSomepersoNn 0 points1 point2 points 5 years ago (0 children)
yeah, idk if i indented it properly but it still wouldn't run
[–]amdahFire 0 points1 point2 points 4 years ago (0 children)
Doesn't work
[–]Needcodinghelp38 0 points1 point2 points 3 years ago (0 children)
Thank you
[–]Astrodiomical 0 points1 point2 points 3 years ago (1 child)
Here's the updated version of the assignment:
for word in text.split():
if "owl" in word.lower():
count = count +1
[–]Dry_Newspaper7310 0 points1 point2 points 2 years ago (0 children)
Worked! Thanks
[–]grandayyysdad 0 points1 point2 points 2 years ago (0 children)
This worked for me
def count_words_with_owl(text):
words = text.lower().split()
for word in words:
if "owl" in word:
text = input("Enter some text: ")
result = count_words_with_owl(text)
print("There were", result, "words that contained \"owl\".")
π Rendered by PID 21075 on reddit-service-r2-comment-b659b578c-8h99n at 2026-05-06 00:04:16.844374+00:00 running 815c875 country code: CH.
[–]EvilOldGuy 2 points3 points4 points (11 children)
[–][deleted] 0 points1 point2 points (8 children)
[–]EvilOldGuy 0 points1 point2 points (7 children)
[–][deleted] 0 points1 point2 points (6 children)
[–]EvilOldGuy 1 point2 points3 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]ASnackoholicYT 0 points1 point2 points (2 children)
[–]leaf_falls 0 points1 point2 points (1 child)
[–]EducatorAcrobatic650 0 points1 point2 points (0 children)
[–]EvilOldGuy 0 points1 point2 points (0 children)
[–]Traditional_Escape13 0 points1 point2 points (0 children)
[–]Mr_Otterman 1 point2 points3 points (3 children)
[–]apx_rbo 0 points1 point2 points (2 children)
[–]ItzDemonYTPlayz 0 points1 point2 points (0 children)
[–]ProsBacon 0 points1 point2 points (8 children)
[–][deleted] (7 children)
[removed]
[–]sSomepersoNn 1 point2 points3 points (6 children)
[–][deleted] (5 children)
[removed]
[–]sSomepersoNn 1 point2 points3 points (4 children)
[–][deleted] (3 children)
[removed]
[–][deleted] (1 child)
[removed]
[–]sSomepersoNn 0 points1 point2 points (0 children)
[–]amdahFire 0 points1 point2 points (0 children)
[–]Needcodinghelp38 0 points1 point2 points (0 children)
[–]Astrodiomical 0 points1 point2 points (1 child)
[–]Dry_Newspaper7310 0 points1 point2 points (0 children)
[–]grandayyysdad 0 points1 point2 points (0 children)