Skip to content

Commit 7f98531

Browse files
committed
Phase
1 parent 3173841 commit 7f98531

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

armstrong_number.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
usrinput=input("Enter a number")
2+
k = []
3+
for i,c in enumerate(usrinput):
4+
m = int(c)
5+
a = m**3
6+
k.append(a)
7+
8+
9+
add=sum(i for i in k)
10+
if add == int(usrinput):
11+
print("The number is an armstrong number")
12+
else:
13+
print("The number is not an armstrong number")

fibonacci_with_loop.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#Fibonacci Series with for loop
2+
3+
num = int(input("enter number of digits you want in series (minimum 2): "))
4+
5+
first = 0
6+
second = 1
7+
8+
print("\nfibonacci series is:")
9+
print(first, ",", second, end=", ")
10+
11+
for i in range(2, num):
12+
next = first + second
13+
print(next, end=", ")
14+
15+
first = second
16+
second = next

fibonacci_with_recursion.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def recur_fibo(n):
2+
if n <= 1:
3+
return n
4+
else:
5+
return(recur_fibo(n-1) + recur_fibo(n-2))
6+
# take input from the user
7+
nterms = int(input("How many terms? "))
8+
# check if the number of terms is valid
9+
if nterms <= 0:
10+
print("Plese enter a positive integer")
11+
else:
12+
print("Fibonacci sequence:")
13+
for i in range(nterms):
14+
print(recur_fibo(i))

0 commit comments

Comments
 (0)