Even the odds

Even the odds

Tags: Algorithms Math Number Theory Pattern Matching

Credit: Ilkka Kokkarinen

Difficulty: Easy

Type: Text

Category: Practice

Time Allowed: 15 s

Description:

Check that the given positive integer n contains only odd digits (1, 3, 5, 7 and 9) when it is written out. Return True if this is the case, and False otherwise. Note that this question is not asking whether the number n itself is odd or even. You therefore will have to look at every digit of the given number before you can proclaim that the number contains no even digits.

To extract the lowest digit of a positive integer n, use the expression n%10. To chop off the lowest digit and keep the rest of the digits, use the expression n//10. Or, if you don’t want to be this fancy, you can first convert the number into a string and whack it from there with string operations.

Test Case Input Expected Output
1 8 False
2 1357975313579 True
3 42 False
4 71358 False
5 0 False

Please register or login to submit solutions to challenges.