Skip to content

Commit

Permalink
Merge pull request #1946 from Piombacciaio/patch-3
Browse files Browse the repository at this point in the history
Update Armstrong_number.py
  • Loading branch information
geekcomputers authored Jul 30, 2023
2 parents 7aafe26 + 9dbdb0e commit 6c511b5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Add two numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
sum = num1 + num2

# Display the sum
print("The sum of"num1,'and'num2,'is',sum)
print(f"The sum of {num1} and {num2} is {sum}")
37 changes: 20 additions & 17 deletions Armstrong_number.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
def is_armstrong_number(number):
total = 0
"""
In number theory, a narcissistic number (also known as a pluperfect digital invariant (PPDI), an Armstrong number (after Michael F. Armstrong) or a plus perfect number),
in a given number base b, is a number that is the total of its own digits each raised to the power of the number of digits.
Source: https://en.wikipedia.org/wiki/Narcissistic_number
NOTE:
this scripts only works for number in base 10
"""

# find the sum of the cube of each digit
temp = number
while temp > 0:
digit = temp % 10
total += digit ** 3
temp //= 10
def is_armstrong_number(number:str):
total:int = 0
exp:int = len(number) #get the number of digits, this will determinate the exponent

digits:list[int] = []
for digit in number: digits.append(int(digit)) #get the single digits
for x in digits: total += x ** exp #get the power of each digit and sum it to the total

# return the result
if number == total:
return True
# display the result
if int(number) == total:
print(number,"is an Armstrong number")
else:
return False
print(number,"is not an Armstrong 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")
number = input("Enter the number : ")
is_armstrong_number(number)
4 changes: 2 additions & 2 deletions BruteForce.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
def findPassword(chars, function, show=50, format_="%s"):

password = None
attempts = 00
size = 01
attempts = 0
size = 1
stop = False

while not stop:
Expand Down
2 changes: 1 addition & 1 deletion FIND FACTORIAL OF A NUMBER.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
def factorial(n):
if n < 0:
return("Oops!Factorial Not Possible")
elif n = 0:
elif n == 0:
return 1
else:
return n*factorial(n-1)
Expand Down
2 changes: 1 addition & 1 deletion FibonacciNumbersWithGenerators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ def fibonacci_generator(n = None):
f0, f1 = f1, fn
n -= 1

for n_fibo in fibonacci(7):
for n_fibo in fibonacci_generator(7):
print(n_fibo)

0 comments on commit 6c511b5

Please sign in to comment.