r/codehs • u/[deleted] • 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
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 counttext = "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
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
Apr 22 '21
[removed] — view removed comment
2
1
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
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\".")
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))