Professional Documents
Culture Documents
Instruction:
Create at least 3 python program that uses diff. types of algorithm (Choose between Brute Force Algorithm,
Recursive Algorithm, Randomized Algorithm, Sorting Algorithm, Sorting Algorithm, Searching Algorithm, and Hashing
Algorithm.)
Kindly label what type of algorithm did you choose.
Randomized Algorithm
if captcha == user_captcha:
return True
return False
def generateCaptcha(n):
chrs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
captcha = ""
while (n):
n -= 1
return captcha
captcha = generateCaptcha(9)
print(captcha)
print("Enter above CAPTCHA:")
usr_captcha = input()
if (checkCaptcha(captcha, usr_captcha)):
print("CAPTCHA Matched")
else:
Output:
91Ql0cvkS
91Ql0cvkS
CAPTCHA Matched
Output:
a5aUSXzFX
a3gsce3td
list_len = len(input_list)
for i in range(list_len):
if input_list[i] == element:
return i
return -1
Sorting Algorithm
print("unsorted list",list1)
for i in range(len(list1)-1):
m_ind = i
for j in range(i+1,len(list1)):
m_ind = j
if list1[i] != list1[m_ind]:
list1[i],list1[m_ind] = list1[m_ind],list1[i]
print(list1)
Output:
How many numbers you want to enter?:10
enter number:7
enter number:4
enter number:0
enter number:1
enter number:8
enter number:9
enter number:5
enter number:3
enter number:2
enter number:6
unsorted list [7, 4, 0, 1, 8, 9, 5, 3, 2, 6]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]