How to check if all the digits of a number are odd in python?

前端 未结 4 922
隐瞒了意图╮
隐瞒了意图╮ 2021-01-26 17:41

I was told to solve a problem in which I would have to find out the number of 4-digit numbers which are all composed of odd digits. I tried the following python code:

         


        
4条回答
  •  清酒与你
    2021-01-26 18:23

    You could try something like this

    def isAllOdd(num):
      if num < 10: return num % 2 == 1;
      return isAllOdd(num % 10) and isAllOdd(int(num / 10))
    

提交回复
热议问题