Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Basic utility functions
6. The is...() functions—exercise
Basic manipulation functions
Replacing and splitting
Summary

Instruction

You did well! Some other popular is-functions available in Python are:

  • str.isalpha() – returns True if all characters in the string are letters.
  • str.isalnum() – returns True if all characters in the string are letters or digits.
  • str.isspace() – returns True if all characters in the string are whitespaces.
  • str.islower() and str.isupper() – return True if all characters in the string are lowercase/uppercase.

Let's do one more exercise with is-functions.

Exercise

John's calculations regarding translation prices have become more complicated. He is now paid the following:

  1. $0.03 for each letter.
  2. $0.02 for each digit.
  3. $0.01 for each whitespace character.

Modify the application so that it calculates the correct price. Print a single sentence:

The price is ${x}.

Stuck? Here's a hint!

Create three counters: one for letters, one for digits, and one for white spaces. Use the isdigit(), isalpha(), and isspace() functions.