Home  >  Article  >  Backend Development  >  Python outputs the number of daffodils

Python outputs the number of daffodils

王林
王林Original
2020-05-07 09:53:046290browse

Python outputs the number of daffodils

The specific code is as follows:

for num in range(100,1000): #如果num在[100,1000)范围,就依次循环取出num的值,第一次取100,下一次取101....最后一次取999
    bai = num // 100 # //取整符号,对100取整,得到百位上的数字
    shi = num // 10 % 10  #得到十位上的数字 %取余符号
    ge = num % 10  #得到个位上的数字
    if(bai**3+shi**3+ge**3==num): #各位数字和等于num
         print(num, end = ' ')   #输出符合if条件的数字  end = ' '使得输出的数不换行,以空格隔开同行输出

Recommended tutorial: python tutorial

The above is the detailed content of Python outputs the number of daffodils. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn