So that is the code I wrote for hangman in python. I need to know of can shorten this code extra additional and make it look extra skilled
# importing random perform
import random, hanged
from word_meaning import meanings
# Dictionary of random phrases
word_dict = '''whistle,
park,
picayune,
connect,
grubby,
gusty,
neck,
obligatory,
day,
compete,
reminiscence,
intervene,
refined,
lumpy,
spiky,
frail'''.break up(',n')
# System chooses a random phrase
rand_word = word_dict[random.randint(0, len(word_dict)-1)]
print('Welcome to HANGMAN.nGuess appropriate letters to finish the hidden phrase, Else hangman will probably be Hanged')
n = len(rand_word)
hidden_word = ((n-1)*'*')
hidden_word_1 = hidden_word.break up('*')
print(f'Hidden Phrase: {hidden_word}*')
print(f'Trace: {meanings[str(rand_word)]}'
That is the dictionary imported from one other file. it provides the that means of the hidden phrase as a touch
possibilities = 10
def user_lose():
world possibilities
print(f'Oops flawed guessn Possibilities Left : {possibilities - 1}')
if possibilities > 1:
possibilities -= 1
user_guess()
else:
hanged.hangman()
hanged.Hangman() that is the perform which reveals pic of hangman. imported from one other file
def user_guess():
world possibilities
if '' in hidden_word_1:
user_input = str(enter('nGuess a letter: ')[0]).decrease()
if user_input in rand_word:
if user_input in hidden_word_1:
user_lose()
else:
if possibilities > 0:
letter_index = rand_word.index(user_input)
letter_index_r = rand_word.rindex(user_input)
hidden_word_1[letter_index] = user_input
hidden_word_1[letter_index_r] = user_input
print(hidden_word_1)
user_guess()
else:
user_lose()
else:
print('Hurrah, You saved Hangman')
user_guess()