Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python3中使用for循环而不是while循环检查armstrong数?_Python_Python 3.x - Fatal编程技术网

在Python3中使用for循环而不是while循环检查armstrong数?

在Python3中使用for循环而不是while循环检查armstrong数?,python,python-3.x,Python,Python 3.x,有没有办法在Python3中使用for循环而不是while循环来编写检查armstrong数的代码 到目前为止,您尝试了什么?首先定义什么是阿姆斯特朗号码,并显示您使用代码的位置,同时请尊重。这里是关于小写的变量名和4个空格的缩进。@Matthias谢谢你指出!现在更正。 # Python Program For Armstrong Number using For Loop number = int(input("\nPlease Enter the Number to Check for

有没有办法在Python3中使用for循环而不是while循环来编写检查armstrong数的代码

到目前为止,您尝试了什么?首先定义什么是阿姆斯特朗号码,并显示您使用代码的位置,同时请尊重。这里是关于小写的变量名和4个空格的缩进。@Matthias谢谢你指出!现在更正。
# Python Program For Armstrong Number using For Loop

number = int(input("\nPlease Enter the Number to Check for Armstrong: "))

# Initializing Sum and Number of Digits
sum = 0
times = 0

# Calculating Number of individual digits
temp = number
while temp > 0:
    times = times + 1
    temp = temp // 10

# Finding Armstrong Number
temp = number
for n in range(1, temp + 1):
    reminder = temp % 10
    sum = sum + (reminder ** times)
    temp //= 10

if number == sum:
    print("\n %d is Armstrong Number.\n" %number)
else:
    print("\n %d is Not a Armstrong Number.\n" %number)