Skip to content

Commit

Permalink
Update Armstrong_number.py
Browse files Browse the repository at this point in the history
The variable name sum is a built-in function name in Python. It is not a good practice to use built-in function names as variable names. It is recommended to use a different variable name, such as total or sum_of_cubes.

The code is using the print function to display the result. It is generally better to return the result instead of printing it, so that the function can be used in other parts of the code.
  • Loading branch information
nikitapandeyy authored Mar 17, 2023
1 parent 263bd95 commit 3151416
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions Armstrong_number.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
def is_armstrong_number(number):
sum = 0
total = 0

# find the sum of the cube of each digit
temp = number
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
digit = temp % 10
total += digit ** 3
temp //= 10

# display the result
if number == sum:
print(number,"is an Armstrong number")
# return the result
if number == total:
return True
else:
print(number,"is not an Armstrong number")
return False

number = int(input("Enter the number : "))
is_armstrong_number(number)
number = int(input("Enter the number: "))
if is_armstrong_number(number):
print(number,"is an Armstrong number")
else:
print(number,"is not an Armstrong number")

0 comments on commit 3151416

Please sign in to comment.