for num in range(100,1000): r=map(lambda x:int(x)**3,str(num)) if sum(r)==num: print(num)
时间: 2024-05-29 10:12:36 浏览: 78
oneliners:一行python代码可隐含算法
As an AI language model, I cannot execute code, but I can explain what this code does.
This code is checking for all three-digit numbers that are equal to the sum of the cubes of their digits.
The code first iterates through all numbers from 100 to 999 using the `range()` function.
For each number, it converts it to a string and then maps the `int()` function to each digit in the string to convert it to an integer. It then cubes each integer using the `**` operator and returns the list of cubes.
The `sum()` function is then used to add up all the cubes, and if the sum equals the original number, it is printed to the console.
This code is an example of a brute-force approach to solving a problem, as it simply checks every possible three-digit number until it finds the ones that meet the criteria.
阅读全文