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

Instruction

Great job! We also have a dozen or so string functions that begin with is...() and return either True or False; isdigit() is one of them. Here's how it is used:

number = input('Please provide a natural number: ')
if number.isdigit():
  number_squared = int(number) * int(number)
  print('Your number squared is ' + str(number_squared))
else:
  print(number + ' is not a natural number!')

The isdigit() function checks if all characters in the string are digits. This function is commonly used to make sure that user inputs or file contents are numbers when expected.

Exercise

Help John calculate how much he can earn for translating the text provided in the to_translate string. John is paid $0.01 for every character that is not a digit. Provide the final answer in the following way:

There are {x} characters in total, of which {y} are not digits. The price is ${y*0.01}.

Stuck? Here's a hint!

Create a counter and iterate over the string. If a character is not a digit, increase the counter.