Giter Club home page Giter Club logo

word-counter's Introduction

Here is a good exercise using computing logic and python methods (specially string ones)

Using a function which takes 1 string as an argument, finds out the number of words in that string, then returns that number.

For example, if the program was used on the string "This is a string.", then the function would return 4.

Assumptions:

Assume that the string will be assigned to a variable and that it will contain at least 1 word. Assume that there will never be 2 or more consecutive spaces in a row within the string. Contractions and possessive words with an apostrophe like "it's" or "Brian's" count as 1 word. Hyphenated words like "ice-cream" count as 1 word. Numbers in the string such as the "007" in "James Bond is 007." count as words There will be no double quotes "" within in the string.

However, the strings that the solution code is being used on are the 3 strings below.

str_1 = "James Bond is 007."

str_2 = "When the moon hits your eye like a big pizza pie, that's amore!"

str_3 = "Anyway, like I was sayin', shrimp is the fruit of the sea. You can barbecue it, boil it, broil it, bake it, saute it. Dey's uh, shrimp-kabobs, shrimp creole, shrimp gumbo. Pan fried, deep fried, stir-fried. There's pineapple, shrimp, lemon shrimp, coconut shrimp, pepper shrimp, shrimp soup, shrimp stew, shrimp salad, shrimp and potatoes, shrimp burger, shrimp sandwich. That- that's about it."

So, for your final solution, copy the above into your .py file and print() 3 calls of your function, once for each of the 3 variables above.

Hints for this problem:

Use string methods to filter out characters besides numbers, letters, spaces, apostrophes, and hyphens. Count the number of spaces in the filtered string and add 1 to that since the string will always contain at least 1 word. This will give you the number of words it contains. You should test your program with many different strings.

word-counter's People

Watchers

Gabriela Serrano avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.