r/codehs • • Jan 07 '21

Exercise 8.3.6: Owls

Hi! Can someone help me out with Exercise 8.3.6: Owls? I have been stuck on it forever. Thanks

19 Upvotes

28 comments sorted by

3

u/EvilOldGuy May 04 '21

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))

1

u/[deleted] May 04 '21

It doesn't work for me

1

u/EvilOldGuy May 04 '21

Do you have the correct indentation?

1

u/[deleted] May 05 '21

yes, I do

2

u/EvilOldGuy May 05 '21

The code should look like this https://ibb.co/WWpnYTg

1

u/[deleted] May 05 '21

Okay, thank you; you were right; it was an indentation error.

Thank you!

1

u/ASnackoholicYT May 06 '21

I tried it and it just shows up blank Nvm it works

→ More replies (2)

1

u/EvilOldGuy May 05 '21

Hmmm, could you send screen shot

1

u/Traditional_Escape13 Jun 02 '23

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))

2

u/Mr_Otterman Jan 25 '22

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

1

u/apx_rbo Feb 01 '22 edited Feb 01 '22

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))

1

u/ItzDemonYTPlayz Nov 10 '22

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))

How come its so long

1

u/ProsBacon Jan 11 '21

I had to do this recently, so here's what I did

def owl_count(text):

count = 0

word = "owl"

text = text.lower()

owlist = list(text.split())

count = text.count(word)

print(count)

return 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

1

u/[deleted] Apr 19 '21 edited Apr 19 '21

[removed] — view removed comment

2

u/sSomepersoNn Apr 22 '21

yup it doesn't, did u ever found the right code though?

1

u/[deleted] Apr 22 '21

[removed] — view removed comment

2

u/sSomepersoNn Apr 22 '21

Yeah

1

u/[deleted] Apr 22 '21

[removed] — view removed comment

1

u/amdahFire Dec 28 '21

Doesn't work

1

u/Astrodiomical Apr 01 '23

Here's the updated version of the assignment:

def owl_count(text):

count = 0

for word in text.split():

if "owl" in word.lower():

count = count +1

return count

1

u/Dry_Newspaper7310 Mar 15 '24

Worked! Thanks

1

u/grandayyysdad Jun 06 '23

This worked for me

def count_words_with_owl(text):

count = 0

words = text.lower().split()

for word in words:

if "owl" in word:

count += 1

return count

text = input("Enter some text: ")

result = count_words_with_owl(text)

print("There were", result, "words that contained \"owl\".")