This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def encrypt(letter, key): | |
# must be single alphabetic character | |
if not letter.isalpha() or len(letter) != 1: | |
return letter | |
# convert to lowercase | |
letter = letter.lower() | |
# convert to numerical value 0 - 25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def InsertionSort(lst): | |
print 'List {}'.format(lst) | |
length = len(lst) | |
for i in range(1, length): | |
value = lst[i] | |
j = i - 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def BubbleSort(numbers): | |
swapped = True | |
maxIndex = len(numbers) - 1 | |
while swapped: | |
swapped = False | |
for i in range(maxIndex): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
number = abs(float(raw_input("Calculate square root of? "))) | |
lowerBound = abs(float(raw_input("Lower bound value? "))) | |
upperBound = abs(float(raw_input("Upper bound value? "))) | |
epsilon = 0.001 | |
while True: | |
guess = (lowerBound + upperBound) / 2 | |
difference = guess**2 - number | |
if abs(difference) <= epsilon: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
number = abs(float(raw_input("Calculate square root of? "))) | |
guess = abs(float(raw_input("Initial guess? "))) | |
epsilon = 0.001 | |
while True: | |
difference = guess**2 - number | |
print('{} : {}'.format(round(guess, 4), round(difference, 4))) | |
if abs(difference) <= epsilon: | |
break |