Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#We've come a long way in this unit! You've learned about #conditionals, loops, functions, and error handling. To end #the unit, let's do a couple

#We've come a long way in this unit! You've learned about
#conditionals, loops, functions, and error handling. To end
#the unit, let's do a couple problems that tie all these
#concepts together.
#
#Write a function called word_count. word_count takes as
#input a string called my_string, and returns as output the
#number of words in the string. For the purposes of this
#problem, you can assume that every space indicates a new
#word; so, the number of words should be one more than the
#number of spaces. You may also assume that any strings are
#not empty, so there should always be at least one word if
#my_string is a string.
#
#Note, though, that it could be the case that a non-string
#is accidentally passed in as the argument for my_string. If
#that happens, an error will arise. If such an error arises,
#you should instead return "Not a string". Otherwise,
#return an integer representing the number of words in the
#string.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions