在Python3中使用for循环而不是while循环检查armstrong数?
有没有办法在Python3中使用for循环而不是while循环来编写检查armstrong数的代码 到目前为止,您尝试了什么?首先定义什么是阿姆斯特朗号码,并显示您使用代码的位置,同时请尊重。这里是关于小写的变量名和4个空格的缩进。@Matthias谢谢你指出!现在更正。在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
# 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)