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

前端 未结 4 936
隐瞒了意图╮
隐瞒了意图╮ 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:32

    for i in range(1000,3001):
      s=str(i)
      if (int(s[0])%2==0 and int(s[1])%2==0 and int(s[2])%2==0 and int(s[3])%2==0):
          print(i,end=",")
    

提交回复
热议问题