Skip to content

Commit

Permalink
Code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-alan-jose committed Mar 17, 2023
1 parent 8ef960b commit cc6a22e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Simple calculator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Program make a simple calculator
# Program to make a simple calculator

# This function adds two numbers
def add(x, y):
Expand All @@ -14,6 +14,8 @@ def multiply(x, y):

# This function divides two numbers
def divide(x, y):
if(y==0):
raise Exception("Divisor cannot be zero")
return x / y


Expand Down
10 changes: 5 additions & 5 deletions binary search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ def binarySearchAppr (arr, start, end, x):
mid = start + (end- start)//2
# If element is present at the middle
if arr[mid] == x:
return mid
return mid
# If element is smaller than mid
elif arr[mid] > x:
return binarySearchAppr(arr, start, mid-1, x)
return binarySearchAppr(arr, start, mid-1, x)
# Else the element greator than mid
else:
return binarySearchAppr(arr, mid+1, end, x)
return binarySearchAppr(arr, mid+1, end, x)
else:
# Element is not found in the array
return -1
arr = sorted(['t','u','t','o','r','i','a','l'])
x ='r'
result = binarySearchAppr(arr, 0, len(arr)-1, x)
x ='r'
result = binarySearchAppr(arr, 0, len(arr)-1, x)
if result != -1:
print ("Element is present at index "+str(result))
else:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion singly_linked_list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cclass Node:
class Node:
def __init__(self, data):
self.data = data
self.next = None
Expand Down

0 comments on commit cc6a22e

Please sign in to comment.