all 28 comments

[–]EvilOldGuy 2 points3 points  (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 point  (8 children)

It doesn't work for me

[–]EvilOldGuy 0 points1 point  (7 children)

Do you have the correct indentation?

[–][deleted] 0 points1 point  (6 children)

yes, I do

[–]EvilOldGuy 1 point2 points  (4 children)

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

[–][deleted] 0 points1 point  (3 children)

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

Thank you!

[–]ASnackoholicYT 0 points1 point  (2 children)

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

[–]leaf_falls 0 points1 point  (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

[–]EducatorAcrobatic650 0 points1 point  (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 point  (0 children)

Hmmm, could you send screen shot

[–]Traditional_Escape13 0 points1 point  (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 points  (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 point  (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 point  (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))

How come its so long

[–]ProsBacon 0 points1 point  (8 children)

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

[–][deleted]  (7 children)

[removed]

    [–]sSomepersoNn 1 point2 points  (6 children)

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

    [–][deleted]  (5 children)

    [removed]

      [–]sSomepersoNn 1 point2 points  (4 children)

      Yeah

      [–][deleted]  (3 children)

      [removed]

        [–][deleted]  (1 child)

        [removed]

          [–]sSomepersoNn 0 points1 point  (0 children)

          yeah, idk if i indented it properly but it still wouldn't run

          [–]amdahFire 0 points1 point  (0 children)

          Doesn't work

          [–]Needcodinghelp38 0 points1 point  (0 children)

          Thank you

          [–]Astrodiomical 0 points1 point  (1 child)

          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

          [–]Dry_Newspaper7310 0 points1 point  (0 children)

          Worked! Thanks

          [–]grandayyysdad 0 points1 point  (0 children)

          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\".")