Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Fibonacci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Program to display the Fibonacci sequence up to n-th term where n is provided by the user

# change this value for a different result
#nterms = 10

# uncomment to take input from the user
nterms = int(input("How many terms? "))

# first two terms
n1 = 0
n2 = 1
count = 0

# check if the number of terms is valid
if nterms <= 0:
print("Please enter a positive integer")
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
else:
print("Fibonacci sequence upto",nterms,":")
while count < nterms:
print(n1,end=' , ')
nth = n1 + n2
# update values
n1 = n2
n2 = nth
count += 1
8 changes: 8 additions & 0 deletions factorial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fact = 1
n = int(input("Enter value:"))

for i in range(1,n+1):
fact = fact * i

print("Factorial of " + str(n) + " is " + str(fact))

19 changes: 19 additions & 0 deletions quick_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def partition(arr,low,high):
i = ( low-1 )
pivot = arr[high]

for j in range(low , high):
if arr[j] <= pivot:
i = i+1
arr[i],arr[j] = arr[j],arr[i]

arr[i+1],arr[high] = arr[high],arr[i+1]
return ( i+1 )


def quickSort(arr,low,high):
if low < high:
pi = partition(arr,low,high)

quickSort(arr, low, pi-1)
quickSort(arr, pi+1, high)