Skip to content

Commit 6c511b5

Browse files
Merge pull request #1946 from Piombacciaio/patch-3
Update Armstrong_number.py
2 parents 7aafe26 + 9dbdb0e commit 6c511b5

File tree

5 files changed

+25
-22
lines changed

5 files changed

+25
-22
lines changed

Add two numbers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
sum = num1 + num2
88

99
# Display the sum
10-
print("The sum of"num1,'and'num2,'is',sum)
10+
print(f"The sum of {num1} and {num2} is {sum}")

Armstrong_number.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
def is_armstrong_number(number):
2-
total = 0
1+
"""
2+
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),
3+
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.
4+
Source: https://en.wikipedia.org/wiki/Narcissistic_number
5+
NOTE:
6+
this scripts only works for number in base 10
7+
"""
38

4-
# find the sum of the cube of each digit
5-
temp = number
6-
while temp > 0:
7-
digit = temp % 10
8-
total += digit ** 3
9-
temp //= 10
9+
def is_armstrong_number(number:str):
10+
total:int = 0
11+
exp:int = len(number) #get the number of digits, this will determinate the exponent
12+
13+
digits:list[int] = []
14+
for digit in number: digits.append(int(digit)) #get the single digits
15+
for x in digits: total += x ** exp #get the power of each digit and sum it to the total
1016

11-
# return the result
12-
if number == total:
13-
return True
17+
# display the result
18+
if int(number) == total:
19+
print(number,"is an Armstrong number")
1420
else:
15-
return False
21+
print(number,"is not an Armstrong number")
1622

17-
number = int(input("Enter the number: "))
18-
if is_armstrong_number(number):
19-
print(number,"is an Armstrong number")
20-
else:
21-
print(number,"is not an Armstrong number")
23+
number = input("Enter the number : ")
24+
is_armstrong_number(number)

BruteForce.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
def findPassword(chars, function, show=50, format_="%s"):
55

66
password = None
7-
attempts = 00
8-
size = 01
7+
attempts = 0
8+
size = 1
99
stop = False
1010

1111
while not stop:

FIND FACTORIAL OF A NUMBER.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
def factorial(n):
44
if n < 0:
55
return("Oops!Factorial Not Possible")
6-
elif n = 0:
6+
elif n == 0:
77
return 1
88
else:
99
return n*factorial(n-1)

FibonacciNumbersWithGenerators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ def fibonacci_generator(n = None):
1414
f0, f1 = f1, fn
1515
n -= 1
1616

17-
for n_fibo in fibonacci(7):
17+
for n_fibo in fibonacci_generator(7):
1818
print(n_fibo)

0 commit comments

Comments
 (0)