Skip to content

Commit

Permalink
Added Python programs Part - 2
Browse files Browse the repository at this point in the history
  • Loading branch information
SarthakKeshari committed Apr 5, 2021
1 parent e32f66c commit 63c03e1
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Numbers/FindDivisors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'''Finding factors of a number'''
import math

n=int(input())

l=[]

for i in range(1,int(math.sqrt(n))+1):
if(n%i==0):
l.append(i)

print(l)
15 changes: 15 additions & 0 deletions Numbers/LargerNumber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'''
Find the larger number n greater than n2 that is divisible by n1.
For eg:
4 7
output: 8
since 8 is the nearest larger number than 7 and it is divisible by 4.
'''


mn=input().split()

m=int(mn[0])
n=int(mn[1])

print(((n//m)+1)*m)
9 changes: 9 additions & 0 deletions Numbers/factorial_of_a_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'''Program to find the factorial of a number using recursion'''

#Taking number from user and finding its factorial using loop
n = int(input())
fact=1
for i in range(1,n+1):
fact*=i

print(fact)
12 changes: 12 additions & 0 deletions Numbers/factorial_of_a_number_recursion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'''Program to find the factorial of a number using recursion'''

def factorial_of_a_number(n):
if n<=1:
return 1
else:
return n * factorial_of_a_number(n-1)

#Taking number from user and passing it to the function

n = int(input())
print(factorial_of_a_number(n))
20 changes: 20 additions & 0 deletions Numbers/fibonacci_series.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'''Fibonacci series upto n value'''

# taking user input-1
n = int(input())

a=0
b=1

if(a<=n):
print(a," ",end="")
if(b<=n):
print(b," ",end="")
c=a+b
while(c<=n):
print(c," ",end="")
a=b
b=c
c=a+b
else:
print("None of the values in fibonacci series are less than",n)

0 comments on commit 63c03e1

Please sign in to comment.