for a in range (1,10): for b in range (1,10): for c in range (1,10): s1=a*100+b*10+c s2=a**3+b**3+c**3 if s1==s2: print (s1)
时间: 2023-05-24 18:05:32 浏览: 120
Python for i in range ()用法详解
5星 · 资源好评率100%
This code is written in Python and it prints out all the Armstrong numbers between 100 and 999.
An Armstrong number is a number that is equal to the sum of its own digits raised to the power of the number of digits in the number.
For example, 153 is an Armstrong number because:
1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153
The code uses three nested loops to generate all three-digit numbers from 100 to 999. For each number, it calculates the sum of its digits raised to the third power and compares it to the original number. If they are equal, it prints out the number.
So, the output of this code will be:
153
370
371
407
These are the four Armstrong numbers between 100 and 999.
阅读全文