← Back to challenges

How Many Decimal Places?

PythonHardnumbersstringsregex

Instructions

Create a function that returns the number of decimal places a number has. Any zeros after the decimal point count towards the number of decimal places.

Examples

get_decimal_places("43.20") ➞ 2

get_decimal_places("400") ➞ 0

get_decimal_places("3.1") ➞ 1

Notes

Return 0 if the number doesn't have any decimal places (see example #2).

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Filter a String