AI Lab
AI Lab
AI Lab
# Constructor
def __init__(self):
while queue:
# Driver code
# Create a graph given in
# the above diagram
g = Graph()
g.addEdge(0, 1)
g.addEdge(0, 2)
g.addEdge(1, 2)
g.addEdge(2, 0)
g.addEdge(2, 3)
g.addEdge(3, 3)
print("Steps: ")
# define punctuation
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
Using sorted()
# Driver code
S = "the Quick brown fox jumPs over the lazY Dog"
# function call
Func(S)
Using sort()
# Python3 program to sort the words of a
# string in alphabetical order
# Driver code
S = "GeekS for geEks"
print(F(S))
def sort_words_alphabetically(input_string):
words = input_string.split()
n = len(words)
for i in range(1, n):
key = words[i]
j = i - 1
while j >= 0 and words[j] > key:
words[j+1] = words[j]
j -= 1
words[j+1] = key
return ' '.join(words)
input_string = 'the Quick brown fox jumPs over the lazY Dog'
output_string = sort_words_alphabetically(input_string)
print(output_string)
import random
def get_random_word_from_wordlist():
wordlist = []
word = random.choice(wordlist)
return word
def get_some_letters(word):
letters = []
temp = '_' * len(word)
character = random.choice(letters)
return temp
def draw_hangman(chances):
if chances == 6:
print("________ ")
print("| | ")
print("| ")
print("| ")
print("| ")
print("| ")
elif chances == 5:
print("________ ")
print("| | ")
print("| 0 ")
print("| ")
print("| ")
print("| ")
elif chances == 4:
print("________ ")
print("| | ")
print("| 0 ")
print("| / ")
print("| ")
print("| ")
elif chances == 3:
print("________ ")
print("| | ")
print("| 0 ")
print("| /| ")
print("| ")
print("| ")
elif chances == 2:
print("________ ")
print("| | ")
print("| 0 ")
print("| /|\ ")
print("| ")
print("| ")
elif chances == 1:
print("________ ")
print("| | ")
print("| 0 ")
print("| /|\ ")
print("| / ")
print("| ")
elif chances == 0:
print("________ ")
print("| | ")
print("| 0 ")
print("| /|\ ")
print("| / \ ")
print("| ")
def start_hangman_game():
word = get_random_word_from_wordlist()
temp = get_some_letters(word)
chances = 7
found = False
while True:
if chances == 0:
print(f"Sorry! You Lost, the word was: {word}")
print("Better luck next time")
break
if found:
found = False
else:
chances -= 1
print()
print("===== Welcome to the Hangman Game =====")
while True:
choice = input("Do you wanna play hangman? (yes/no): ")
if 'yes' in choice.lower():
start_hangman_game()
elif 'no' in choice.lower():
print('Quitting the game...')
break
else:
print("Please enter a valid choice.")
print("\n")