├── car-sales.csv ├── adjacency_list.py ├── bfs.py ├── nqueens.py ├── hangman_art.py ├── hangman.py ├── waterjugmanual .py └── hangman_words.py /car-sales.csv: -------------------------------------------------------------------------------- 1 | Make,Colour,Odometer (KM),Doors,Price 2 | Toyota,White,150043,4,"$4,000.00" 3 | Honda,Red,87899,4,"$5,000.00" 4 | Toyota,Blue,32549,3,"$7,000.00" 5 | BMW,Black,11179,5,"$22,000.00" 6 | Nissan,White,213095,4,"$3,500.00" 7 | Toyota,Green,99213,4,"$4,500.00" 8 | Honda,Blue,45698,4,"$7,500.00" 9 | Honda,Blue,54738,4,"$7,000.00" 10 | Toyota,White,60000,4,"$6,250.00" 11 | Nissan,White,31600,4,"$9,700.00" -------------------------------------------------------------------------------- /adjacency_list.py: -------------------------------------------------------------------------------- 1 | graph={ 2 | 'A':['B','C'], 3 | 'B':['D','E'], 4 | 'C':['F'], 5 | 'D':[], 6 | 'E':['F'], 7 | 'F':[],} 8 | visited=set() 9 | def dfs(visited,graph,node): 10 | if node not in visited: 11 | print(node) 12 | visited.add(node) 13 | for neighbour in graph[node]: 14 | dfs(visited,graph,neighbour) 15 | print("following is the depth-first search") 16 | dfs(visited,graph,'A') 17 | -------------------------------------------------------------------------------- /bfs.py: -------------------------------------------------------------------------------- 1 | graph={ 2 | 'P':['Q','R','S'], 3 | 'Q':['P','R'], 4 | 'R':['P','Q','T'], 5 | 'T':['R'], 6 | 'S':['P'] 7 | } 8 | visited=[] 9 | queue=[] 10 | def bfs(visited,graph,node): 11 | visited.append(node) 12 | queue.append(node) 13 | while queue: 14 | m=queue.pop(0) 15 | print(m,end=" ") 16 | for neighbour in graph[m]: 17 | if neighbour not in visited: 18 | visited.append(neighbour) 19 | queue.append(neighbour) 20 | print("following is the breath first search") 21 | bfs(visited,graph,'P') 22 | -------------------------------------------------------------------------------- /nqueens.py: -------------------------------------------------------------------------------- 1 | class solution: 2 | def __init__(self): 3 | self.MAX=20 4 | self.A =[0]*self.MAX 5 | def placement(self,i,j): 6 | for k in range(1,i): 7 | if (self.A[k]==j) or abs(self.A[k]-j) == abs(k-i): 8 | return False 9 | print(self.A) 10 | return True 11 | def printplacedqueen(self,N): 12 | print('Arrangment-->') 13 | print() 14 | 15 | for i in range(1,N+1): 16 | for j in range(1,N+1): 17 | if self.A[i] !=j: 18 | print('\t_',end='') 19 | else: 20 | print('\tQ',end ='') 21 | print() 22 | print() 23 | 24 | def N_Queens(self,i,j): 25 | for k in range(1,N+1): 26 | if self.placement(i,k): 27 | self.A[i]=k 28 | if i==N: 29 | self.printplacedqueen(N) 30 | else: 31 | self.N_Queens(i+1,N) 32 | 33 | N=int(input("enter the queens value:")) 34 | obj=solution() 35 | obj.N_Queens(1,N) 36 | 37 | -------------------------------------------------------------------------------- /hangman_art.py: -------------------------------------------------------------------------------- 1 | stages = [''' 2 | +---+ 3 | | | 4 | O | 5 | /|\ | 6 | / \ | 7 | | 8 | ========= 9 | ''', ''' 10 | +---+ 11 | | | 12 | O | 13 | /|\ | 14 | / | 15 | | 16 | ========= 17 | ''', ''' 18 | +---+ 19 | | | 20 | O | 21 | /|\ | 22 | | 23 | | 24 | ========= 25 | ''', ''' 26 | +---+ 27 | | | 28 | O | 29 | /| | 30 | | 31 | | 32 | =========''', ''' 33 | +---+ 34 | | | 35 | O | 36 | | | 37 | | 38 | | 39 | ========= 40 | ''', ''' 41 | +---+ 42 | | | 43 | O | 44 | | 45 | | 46 | | 47 | ========= 48 | ''', ''' 49 | +---+ 50 | | | 51 | | 52 | | 53 | | 54 | | 55 | ========= 56 | '''] 57 | 58 | logo = ''' 59 | _ 60 | | | 61 | | |__ __ _ _ __ __ _ _ __ ___ __ _ _ __ 62 | | '_ \ / _` | '_ \ / _` | '_ ` _ \ / _` | '_ \ 63 | | | | | (_| | | | | (_| | | | | | | (_| | | | | 64 | |_| |_|\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| 65 | __/ | 66 | |___/ ''' 67 | 68 | 69 | -------------------------------------------------------------------------------- /hangman.py: -------------------------------------------------------------------------------- 1 | import random 2 | from hangman_words import word_list 3 | from hangman_art import stages,logo 4 | chose_word =random.choice(word_list) 5 | lives=6 6 | #lives=6 if len(chosen_word)>=6 else 6 7 | print(f'pssst, the solution is {chose_word}.') 8 | print(logo) 9 | print(len(stages)) 10 | display=[] 11 | guessed=[] 12 | for i in range(len(chose_word)): 13 | display.append("_") 14 | while "_" in display and lives>0: 15 | guess=input("guess a letter:").lower() 16 | if len(guess==1) and guess.isalpha(): 17 | if guess in guessed: 18 | print("letter already present") 19 | continue 20 | guessed.append(guess) 21 | for i in range(len(chose_word)): 22 | letter=chose_word[i] 23 | if letter ==guess: 24 | display[i]=letter 25 | if guess not in chose_word: 26 | if lives>0: 27 | lives=lives-1 28 | if lives==0: 29 | print(stages[lives]) 30 | print(f'the solution is {chose_word}.lower()') 31 | print("you loose") 32 | exit(1) 33 | print(f"{' '.joinI(display)}") 34 | print(lives) 35 | print(stages[lives]) 36 | else: 37 | print("gess should be a character rather than a word") 38 | else: 39 | print("you have won") 40 | -------------------------------------------------------------------------------- /waterjugmanual .py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | # Input capacities and initial/final states for jugs 4 | a = int(input("Enter Jug A Capacity: ")) 5 | b = int(input("Enter Jug B Capacity: ")) 6 | ai = int(input("Initially Water in Jug A: ")) 7 | bi = int(input("Initially Water in Jug B: ")) 8 | af = int(input("Final State of Jug A: ")) 9 | bf = int(input("Final State of Jug B: ")) 10 | 11 | # Check for negative values 12 | if a <= 0 or b <= 0: 13 | print("Jug capacities must be positive.") 14 | exit(1) 15 | if ai < 0 or bi < 0 or af < 0 or bf < 0: 16 | print("Negative values are not allowed.") 17 | exit(1) 18 | 19 | # Define the water jug solver function 20 | def wjug(a, b, ai, bi, af, bf): 21 | print("List Of Operations You Can Do:\n") 22 | print("1. Fill Jug A Completely") 23 | print("2. Fill Jug B Completely") 24 | print("3. Empty Jug A Completely") 25 | print("4. Empty Jug B Completely") 26 | print("5. Pour From Jug A till Jug B is full or A becomes empty") 27 | print("6. Pour From Jug B till Jug A is full or B becomes empty") 28 | print("7. Pour all from Jug B to Jug A") 29 | print("8. Pour all from Jug A to Jug B") 30 | 31 | # Loop until the final state is reached 32 | while ai != af or bi != bf: 33 | op = int(input("Enter the Operation (1-8): ")) 34 | 35 | if op == 1: # Fill Jug A completely 36 | ai = a 37 | elif op == 2: # Fill Jug B completely 38 | bi = b 39 | elif op == 3: # Empty Jug A 40 | ai = 0 41 | elif op == 4: # Empty Jug B 42 | bi = 0 43 | elif op == 5: # Pour from A to B 44 | pour_amount = min(ai, b - bi) 45 | ai -= pour_amount 46 | bi += pour_amount 47 | elif op == 6: # Pour from B to A 48 | pour_amount = min(bi, a - ai) 49 | bi -= pour_amount 50 | ai += pour_amount 51 | elif op == 7: # Pour all from B to A 52 | pour_amount = min(bi, a - ai) 53 | ai += pour_amount 54 | bi -= pour_amount 55 | elif op == 8: # Pour all from A to B 56 | pour_amount = min(ai, b - bi) 57 | bi += pour_amount 58 | ai -= pour_amount 59 | else: 60 | print("Invalid operation. Please choose a number between 1 and 8.") 61 | continue 62 | 63 | print(f"Jug A: {ai}, Jug B: {bi}") 64 | 65 | if ai == af and bi == bf: 66 | print("Final State Reached: Jug A =", ai, ", Jug B =", bi) 67 | return 68 | 69 | 70 | 71 | print("Final State Reached: Jug A =", ai, ", Jug B =", bi) 72 | 73 | # Check if the final state is achievable using GCD 74 | gcd = math.gcd(a, b) 75 | 76 | if (af <= a and bf <= b) and (af % gcd == bf % gcd == 0): 77 | wjug(a, b, ai, bi, af, bf) 78 | else: 79 | print("The final state is not achievable with the given capacities.") 80 | exit(1) 81 | -------------------------------------------------------------------------------- /hangman_words.py: -------------------------------------------------------------------------------- 1 | word_list = [ 2 | 'abruptly', 3 | 'absurd', 4 | 'abyss', 5 | 'affix', 6 | 'askew', 7 | 'avenue', 8 | 'awkward', 9 | 'axiom', 10 | 'azure', 11 | 'bagpipes', 12 | 'bandwagon', 13 | 'banjo', 14 | 'bayou', 15 | 'beekeeper', 16 | 'blitz', 17 | 'blizzard', 18 | 'boggle', 19 | 'bookworm', 20 | 'boxcar', 21 | 'boxful', 22 | 'buckaroo', 23 | 'buffalo', 24 | 'buffoon', 25 | 'buxom', 26 | 'buzzard', 27 | 'buzzing', 28 | 'buzzwords', 29 | 'caliph', 30 | 'cobweb', 31 | 'cockiness', 32 | 'croquet', 33 | 'crypt', 34 | 'curacao', 35 | 'cycle', 36 | 'daiquiri', 37 | 'dirndl', 38 | 'disavow', 39 | 'dizzying', 40 | 'duplex', 41 | 'dwarves', 42 | 'embezzle', 43 | 'equip', 44 | 'espionage', 45 | 'euouae', 46 | 'exodus', 47 | 'faking', 48 | 'fishhook', 49 | 'fixable', 50 | 'fjord', 51 | 'flapjack', 52 | 'flopping', 53 | 'fluffiness', 54 | 'flyby', 55 | 'foxglove', 56 | 'frazzled', 57 | 'frizzled', 58 | 'fuchsia', 59 | 'funny', 60 | 'gabby', 61 | 'galaxy', 62 | 'galvanize', 63 | 'gazebo', 64 | 'giaour', 65 | 'gizmo', 66 | 'glowworm', 67 | 'glyph', 68 | 'gnarly', 69 | 'gnostic', 70 | 'gossip', 71 | 'grogginess', 72 | 'haiku', 73 | 'haphazard', 74 | 'hyphen', 75 | 'iatrogenic', 76 | 'icebox', 77 | 'injury', 78 | 'ivory', 79 | 'ivy', 80 | 'jackpot', 81 | 'jaundice', 82 | 'jawbreaker', 83 | 'jaywalk', 84 | 'jazziest', 85 | 'jazzy', 86 | 'jelly', 87 | 'jigsaw', 88 | 'jinx', 89 | 'jiujitsu', 90 | 'jockey', 91 | 'jogging', 92 | 'joking', 93 | 'jovial', 94 | 'joyful', 95 | 'juicy', 96 | 'jukebox', 97 | 'jumbo', 98 | 'kayak', 99 | 'kazoo', 100 | 'keyhole', 101 | 'khaki', 102 | 'kilobyte', 103 | 'kiosk', 104 | 'kitsch', 105 | 'kiwifruit', 106 | 'klutz', 107 | 'knapsack', 108 | 'larynx', 109 | 'lengths', 110 | 'lucky', 111 | 'luxury', 112 | 'lymph', 113 | 'marquis', 114 | 'matrix', 115 | 'megahertz', 116 | 'microwave', 117 | 'mnemonic', 118 | 'mystify', 119 | 'naphtha', 120 | 'nightclub', 121 | 'nowadays', 122 | 'numbskull', 123 | 'nymph', 124 | 'onyx', 125 | 'ovary', 126 | 'oxidize', 127 | 'oxygen', 128 | 'pajama', 129 | 'peekaboo', 130 | 'phlegm', 131 | 'pixel', 132 | 'pizazz', 133 | 'pneumonia', 134 | 'polka', 135 | 'pshaw', 136 | 'psyche', 137 | 'puppy', 138 | 'puzzling', 139 | 'quartz', 140 | 'queue', 141 | 'quips', 142 | 'quixotic', 143 | 'quiz', 144 | 'quizzes', 145 | 'quorum', 146 | 'razzmatazz', 147 | 'rhubarb', 148 | 'rhythm', 149 | 'rickshaw', 150 | 'schnapps', 151 | 'scratch', 152 | 'shiv', 153 | 'snazzy', 154 | 'sphinx', 155 | 'spritz', 156 | 'squawk', 157 | 'staff', 158 | 'strength', 159 | 'strengths', 160 | 'stretch', 161 | 'stronghold', 162 | 'stymied', 163 | 'subway', 164 | 'swivel', 165 | 'syndrome', 166 | 'thriftless', 167 | 'thumbscrew', 168 | 'topaz', 169 | 'transcript', 170 | 'transgress', 171 | 'transplant', 172 | 'triphthong', 173 | 'twelfth', 174 | 'twelfths', 175 | 'unknown', 176 | 'unworthy', 177 | 'unzip', 178 | 'uptown', 179 | 'vaporize', 180 | 'vixen', 181 | 'vodka', 182 | 'voodoo', 183 | 'vortex', 184 | 'voyeurism', 185 | 'walkway', 186 | 'waltz', 187 | 'wave', 188 | 'wavy', 189 | 'waxy', 190 | 'wellspring', 191 | 'wheezy', 192 | 'whiskey', 193 | 'whizzing', 194 | 'whomever', 195 | 'wimpy', 196 | 'witchcraft', 197 | 'wizard', 198 | 'woozy', 199 | 'wristwatch', 200 | 'wyvern', 201 | 'xylophone', 202 | 'yachtsman', 203 | 'yippee', 204 | 'yoked', 205 | 'youthful', 206 | 'yummy', 207 | 'zephyr', 208 | 'zigzag', 209 | 'zigzagging', 210 | 'zilch', 211 | 'zipper', 212 | 'zodiac', 213 | 'zombie', 214 | ] 215 | --------------------------------------------------------------------------------