diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6809c20 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "C:\\Users\\azadk\\AppData\\Local\\Programs\\Python\\Python38-32\\python.exe" +} \ No newline at end of file diff --git a/Arrays/games.0.3.1.py b/Arrays/games.0.3.1.py index 96ac900..123bc3b 100644 --- a/Arrays/games.0.3.1.py +++ b/Arrays/games.0.3.1.py @@ -35,7 +35,8 @@ print("Enter the number of points you want play for: ") points = int(input()) while player_score < points and computer_score < points: - print(f"computer score = {computer_score}\t {player1} score = {player_score}") + print( + f"computer score = {computer_score}\t {player1} score = {player_score}") print("Rock 👊\n") print("Paper 🤚\n") print("Scissor ✌\n") diff --git a/python/BubbleSort.py b/python/BubbleSort.py index 177f200..82db70f 100644 --- a/python/BubbleSort.py +++ b/python/BubbleSort.py @@ -1,15 +1,36 @@ -#Python program for implementation og Bubble Sort -#Making Function to perform bubbleSort +# Python program for implementation og Bubble Sort +# Making Function to perform bubbleSort def bubbleSort(arrays): - for passnum in range(len(arrays)-1,0,-1): + for passnum in range(len(arrays)-1, 0, -1): for i in range(passnum): - if arrays[i]>arrays[i+1]: + if arrays[i] > arrays[i+1]: temp = arrays[i] arrays[i] = arrays[i+1] arrays[i+1] = temp -#initialize the array -arrays = [5,2,9,1,7,3,4,505,200] -#Performing bubbleSort Function + + +# initialize the array +arrays = [5, 2, 9, 1, 7, 3, 4, 505, 200] +# Performing bubbleSort Function bubbleSort(arrays) -#Printing array after bubble sort +# Printing array after bubble sort print(arrays) + + +# Anotherway of implementing Bubble short inpython + +def bubble_short(sequence): + indexing_length = len(sequence) - 1 + shorted = False + + while not shorted: + shorted = True + for i in range(indexing_length): + if sequence[i] > sequence[i+1]: + shorted = False + sequence[i], sequence[i+1] = sequence[i+1], sequence[i] + return sequence + + +print(bubble_short([89, 399, 757, 257, 372, 553, + 241, 216, 48, 355, 41, 34, 798, 470, 751])) diff --git a/python/NumberToEnglish.py b/python/NumberToEnglish.py index 3efbad0..bb7f5fe 100644 --- a/python/NumberToEnglish.py +++ b/python/NumberToEnglish.py @@ -28,10 +28,14 @@ def NumToEnglish(num): num = str(num) resulted_string = "" - initial_dict = {0: "zero", 1: "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six", 7: "seven", 8: "eight", - 9: "nine", 10: "ten", 11: "eleven", 12: "twelve", 13: "thirteen", 14: "fourteen", 15: "fifteen", - 16: "sixteen", 17: "seventeen", 18: "eighteen", 19: "nineteen", 20: "twenty", 30: "thirty", - 40: "forty", 50: "fifty", 60: "sixty", 70: "seventy", 80: "eighty", 90: "ninety", 100: "hundred"} + initial_dict = {0: "zero", 1: "one", 2: "two", 3: "three", + 4: "four", 5: "five", 6: "six", 7: "seven", 8: "eight", + 9: "nine", 10: "ten", 11: "eleven", 12: "twelve", + 13: "thirteen", 14: "fourteen", 15: "fifteen", + 16: "sixteen", 17: "seventeen", 18: "eighteen", + 19: "nineteen", 20: "twenty", 30: "thirty", + 40: "forty", 50: "fifty", 60: "sixty", 70: "seventy", + 80: "eighty", 90: "ninety", 100: "hundred"} if int(num) in initial_dict.keys(): return initial_dict.get(int(num)) @@ -40,14 +44,18 @@ def NumToEnglish(num): for i in range(length_of_number): if i == 0 and int(num[i]) > 0: - resulted_string = str(initial_dict.get(int(num[i]))) + " " + str(initial_dict.get(100)) + resulted_string = str(initial_dict.get( + int(num[i]))) + " " + str(initial_dict.get(100)) elif i == 1 and int(num[1]) == 1: - resulted_string = resulted_string + " " + str(initial_dict.get(int(num[1:3]))) + resulted_string = resulted_string + " " + \ + str(initial_dict.get(int(num[1:3]))) elif i == 1 and int(num[1]) > 1: - resulted_string = resulted_string + " " + str(initial_dict.get(int(num[1]) * 10)) + resulted_string = resulted_string + " " + \ + str(initial_dict.get(int(num[1]) * 10)) elif i == 2 and int(num[1]) != 1 and int(num[i]) > 0: print(num[1]) - resulted_string = resulted_string + " " + str(initial_dict.get(int(num[i]))) + resulted_string = resulted_string + " " + \ + str(initial_dict.get(int(num[i]))) return resulted_string.strip() diff --git a/python/quickShort.py b/python/quickShort.py new file mode 100644 index 0000000..25a5e3a --- /dev/null +++ b/python/quickShort.py @@ -0,0 +1,32 @@ +''' +The way this algorithm works is +first we define a pivot point as a reference we can use any point as a +reference but here we are using last value from our input list + +and then we make two list namesd as lower and heigher and we append value +respective to the pivot point to the respective list + +and we done the same process over and over again till the condition breaks +''' + +def quick_short(List): + length = len(List) + lower = [] + heigher = [] + if length <= 1: + return List + else: + pivot = List.pop() + for i in List: + if i >= pivot: + heigher.append(i) + else: + lower.append(i) + return quick_short(lower) + [pivot] + quick_short(heigher) + +x = quick_short([ +89,399,757,257,372,553,241,216,48,355,41,34,798,470,751,285,288,768,563,2,638,113,153,394,500,715,495,217,578,625,628,27,345,329,579,677,331,211,354,646,715,595,784,552,515,226,598,533,508,332,515,789,521,261,117,415,712,604,93,144,595,38,423,798,165,472,573,771,312,330,92,731,775,579,140,329,530,439,276,166,395,233,41,314,141,201,688,383,763,606,87,672,207,564,687,285,24,216,394,675,652,302,33,786,540,173,664,624,58,190,792,43,178,212,557,231,389,641,586,504,301,92,573,126,85,678,27,480,765,637,255,193,300,693,74,16,146,479,54,87,503,215,161,208,673,83,180,520,591,786,559,486,12, +]) +x = set(x) +print(x) +