Home > Article > Backend Development > 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!