Skip to content
Merged

Key3 #151

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
21 changes: 21 additions & 0 deletions Python/program-14/git.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#fibonacci series
nterms = int(input("How many terms? "))

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

if nterms <= 0:
print("Please enter a positive integer")
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
else:
print("Fibonacci sequence:")
while count < nterms:
print(n1)
nth = n1 + n2
# update values
n1 = n2
n2 = nth
count += 1
1 change: 1 addition & 0 deletions Python/program-14/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
program to print fibonacci series
22 changes: 22 additions & 0 deletions Python/program-15/git1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Program to check if a number is prime or not

num = 407

# To take input from the user
#num = int(input("Enter a number: "))

# prime numbers are greater than 1
if num > 1:
# check for factors
for i in range(2,num):
if (num % i) == 0:
print(num,"is not a prime number")
print(i,"times",num//i,"is",num)
break
else:
print(num,"is a prime number")

# if input number is less than
# or equal to 1, it is not prime
else:
print(num,"is not a prime number")
1 change: 1 addition & 0 deletions Python/program-15/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
program to check whether a number is prime or not
36 changes: 36 additions & 0 deletions Python/program-16/git2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Returns index of x in arr if present, else -1
def binary_search(arr, low, high, x):

# Check base case
if high >= low:

mid = (high + low) // 2

# If element is present at the middle itself
if arr[mid] == x:
return mid

# If element is smaller than mid, then it can only
# be present in left subarray
elif arr[mid] > x:
return binary_search(arr, low, mid - 1, x)

# Else the element can only be present in right subarray
else:
return binary_search(arr, mid + 1, high, x)

else:
# Element is not present in the array
return -1

# Test array
arr = [ 2, 3, 4, 10, 40 ]
x = 10

# Function call
result = binary_search(arr, 0, len(arr)-1, x)

if result != -1:
print("Element is present at index", str(result))
else:
print("Element is not present in array")
1 change: 1 addition & 0 deletions Python/program-16/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python program for binary search
17 changes: 17 additions & 0 deletions Python/program-18/git3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Python3 program to find simple interest
# for given principal amount, time and
# rate of interest.


def simple_interest(p,t,r):
print('The principal is', p)
print('The time period is', t)
print('The rate of interest is',r)

si = (p * t * r)/100

print('The Simple Interest is', si)
return si

# Driver code
simple_interest(8, 6, 8)
1 change: 1 addition & 0 deletions Python/program-18/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python program for simple interest