0% found this document useful (0 votes)
3 views

Assignment 2

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Assignment 2

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Assignment

words = ['holiday', 'american', 'restaurant', 'computer', 'highschool', 'programming']


random_word = random.choice(words)
count = 0
guess_list = []

while True: #repeatedly asks you to guess the letter in a random word
guess = str(input("Guess a letter: "))
guess = guess.lower()

if guess not in guess_list:


if guess in random_word: #checks if the letter you input is in the random generated word
print("Yay, its in the word")

else:
count += 1
print("Not in the word, attempts: %d" % count)

if count > 5:
print("You have reached max attempts")
print("Sorry, but hangman died! You lose")
break

else:
print("You have already guessed {}. Try again".format(guess))
print(set(guess_list))

guess_list.append(guess)
output:
Guess a letter: c
Yay, its in the word
Guess a letter: e
Yay, its in the word
Guess a letter: e
You have already guessed e. Try again
{'e', 'c'}
Guess a letter: e
You have already guessed e. Try again
{'e', 'c'}
Guess a letter: w
Not in the word, attempts: 1
Guess a letter: m
Yay, its in the word
Guess a letter: m
You have already guessed m. Try again
{'w', 'm', 'e', 'c'}
Guess a letter:

2)

You might also like