-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #455 from amazing-AK/master
Added a Password Generator
- Loading branch information
Showing
3 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
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
52 changes: 52 additions & 0 deletions
52
Program's_Contributed_By_Contributors/Python_Programs/binarySearch.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import random | ||
|
||
# Binary Search | ||
|
||
|
||
def binarySearch(sortedList, key, start, end): | ||
if start <= end: | ||
middleIndex = (start + end) // 2 | ||
middleElement = sortedList[middleIndex] | ||
|
||
if middleElement == key: | ||
return middleIndex | ||
elif middleElement < key: | ||
location = binarySearch(sortedList, key, middleIndex + 1, end) | ||
else: | ||
location = binarySearch(sortedList, key, start, middleIndex - 1) | ||
|
||
return location | ||
|
||
return -1 | ||
|
||
|
||
myList = random.sample(range(0, 1000), 10) | ||
target = int(input('Enter target: ')) | ||
location = binarySearch(myList, target, 0, len(myList) - 1) | ||
print(f'Element found at index {location}.') | ||
|
||
|
||
# Old version | ||
# start,end | ||
def binarySearch(key, start, end): | ||
# If start and end are adjacent elements, element does not exist | ||
if end == start + 1: | ||
return -1 | ||
middleElementIndex = (start + end) // 2 | ||
middleElement = myList[middleElementIndex] | ||
if key == middleElement: | ||
return middleElementIndex | ||
if key >= middleElement: | ||
start = middleElementIndex | ||
x = binarySearch(key, start, end) | ||
else: | ||
end = middleElementIndex | ||
x = binarySearch(key, start, end) | ||
return x | ||
|
||
|
||
myList = [1, 2, 3, 4, 5, 12, 20, 30, 40, 45, 50, 70] | ||
elementToBeFound = 5 | ||
print(f'List: {myList}') | ||
x = binarySearch(elementToBeFound, 0, len(myList) - 1) | ||
print(f'{elementToBeFound} found at index: {x}') |
16 changes: 16 additions & 0 deletions
16
Program's_Contributed_By_Contributors/Python_Programs/passwordGenerator.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import string | ||
import random | ||
|
||
allLetters = string.ascii_letters | ||
allNumbers = string.digits | ||
allSymbols = string.punctuation | ||
|
||
allCharacters = allLetters + allNumbers + allSymbols | ||
passwordLength = 20 | ||
|
||
|
||
temp = random.sample(allCharacters, passwordLength) | ||
password = "".join(temp) | ||
|
||
|
||
print(f"Generated Password: {password}") |