subject
Computers and Technology, 09.09.2019 19:10 aris35

#now let's make things a little more challenging.
#
#last exercise, you wrote a function called word_count that
#counted the number of words in a string essentially by
#counting the spaces. however, if there were multiple spaces
#in a row, it would incorrectly add additional words. for
#example, it would have counted the string "hi david" as
#4 words instead of 2 because there are two additional
#spaces.
#
#revise your word_count method so that if it encounters
#multiple consecutive spaces, it does *not* count an
#additional word. for example, these three strings should
#all be counted as having two words:
#
# "hi david"
# "hi david"
# "hi david"
#
#other than ignoring consecutive spaces, the directions are
#the same: write a function called word_count that returns an
#integer representing the number of words in the string, or
#return "not a string" if the input isn't a string. you may
#assume that if the input is a string, it starts with a
#letter word instead of a space.
#write your function here!
#below are some lines of code that will test your function.
#you can change the value of the variable(s) to test your
#function with different inputs.
#
#if your function works correctly, this will originally
#print:
#word count: 4
#word count: 2
#word count: not a string
#word count: not a string
#word count: not a string
print("word count: ", word_count("four words are here! "))
print("word count: ", word_count("hi david"))
print("word count: ", word_count(5))
print("word count: ", word_count(5.1))
print("word count: ", word_count(true))

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:00
Determine whether the following careers would require training or college.
Answers: 1
question
Computers and Technology, 23.06.2019 08:00
Michael has written an e-mail to his employees that describes a new product special that will be introduced to the customers next week. by taking time to make sure the e-mail is well written, logical, and organized, michael has made sure his message has the characteristics of a) effective communicationb) ineffective communicationc) barriers to communicationd) workplace communication
Answers: 2
question
Computers and Technology, 24.06.2019 01:30
Could you find out how im still getting an 83 percent on this in edhesive a = input("enter an animal: ") s = input ("enter a sound: ") e = "e-i-e-i-o" print ("old macdonald had a farm, " + e) print ("and on his farm he had a " + a + "," + e) print ("with a " + s + "-" + s + " here and a " + s + "-" + s + " there") print ("here a " + s+ " there a " + s) print ("everywhere a " + s + "-" + s ) print ("old macdonald had a farm, " + e)
Answers: 2
question
Computers and Technology, 24.06.2019 04:30
How do you share someone else’s tweet with your own twitter followers?
Answers: 1
You know the right answer?
#now let's make things a little more challenging.
#
#last exercise, you wrote a functi...
Questions
question
Mathematics, 23.03.2021 14:00
question
Engineering, 23.03.2021 14:00
question
Mathematics, 23.03.2021 14:00
question
Mathematics, 23.03.2021 14:00
question
English, 23.03.2021 14:00
question
Mathematics, 23.03.2021 14:00
question
History, 23.03.2021 14:00
Questions on the website: 13722360