Skip to content

Commit cc6a22e

Browse files
Code improvements
1 parent 8ef960b commit cc6a22e

4 files changed

+9
-7
lines changed

Simple calculator.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Program make a simple calculator
1+
# Program to make a simple calculator
22

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

1515
# This function divides two numbers
1616
def divide(x, y):
17+
if(y==0):
18+
raise Exception("Divisor cannot be zero")
1719
return x / y
1820

1921

binary search.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ def binarySearchAppr (arr, start, end, x):
44
mid = start + (end- start)//2
55
# If element is present at the middle
66
if arr[mid] == x:
7-
return mid
7+
return mid
88
# If element is smaller than mid
99
elif arr[mid] > x:
10-
return binarySearchAppr(arr, start, mid-1, x)
10+
return binarySearchAppr(arr, start, mid-1, x)
1111
# Else the element greator than mid
1212
else:
13-
return binarySearchAppr(arr, mid+1, end, x)
13+
return binarySearchAppr(arr, mid+1, end, x)
1414
else:
1515
# Element is not found in the array
1616
return -1
1717
arr = sorted(['t','u','t','o','r','i','a','l'])
18-
x ='r'
19-
result = binarySearchAppr(arr, 0, len(arr)-1, x)
18+
x ='r'
19+
result = binarySearchAppr(arr, 0, len(arr)-1, x)
2020
if result != -1:
2121
print ("Element is present at index "+str(result))
2222
else:

singly_linked_list.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cclass Node:
1+
class Node:
22
def __init__(self, data):
33
self.data = data
44
self.next = None

0 commit comments

Comments
 (0)