如何使用Python打印自恋(阿姆斯壮)数字?
要打印自恋数字,我们首先来看一下它的定义。它是一个数字,它是其自己的数字之和,每个数字均提高为数字的幂。例如,1、153、370都是自恋数字。您可以通过运行以下代码来打印这些数字
def print_narcissistic_nums(start, end):
for i in range(start, end + 1):
# Get the digits from the number in a list:
digits = list(map(int, str(i)))
total = 0
length = len(digits)
for d in digits:
total += d ** length
if total == i:
print(i)
print_narcissistic_nums(1, 380)这将给出输出
1 2 3 4 5 6 7 8 9 153 370 371
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿