Skip to content

Instantly share code, notes, and snippets.

@guidani
Created October 22, 2021 19:37
Show Gist options
  • Save guidani/d98a26c250b7d2df720749bb49229519 to your computer and use it in GitHub Desktop.
Save guidani/d98a26c250b7d2df720749bb49229519 to your computer and use it in GitHub Desktop.
jogo da forca em python
def main():
palavras_chutadas = []
tela = cria_exibicao()
total_tentativas = 6
acertou_palavra = False
forca = False
while not forca and not acertou_palavra:
print('-'*30)
chute = input('Chute: ')
palavras_chutadas.append(chute)
print(palavras_chutadas)
preenche_exibicao(chute, tela)
if chute not in tela:
total_tentativas -= 1
print(f'TELA: {tela}')
print(f'tentativas restantes: {total_tentativas}')
else:
print(f'TELA: {tela}')
if total_tentativas == 0:
print('FORCA')
break
if not falta_letra(tela):
print('!!!PARABÉNS!!!')
acertou_palavra = True
def falta_letra(tela):
falta = '_' in tela
return falta
def preenche_exibicao(letra, tela):
for i in range(len(palavra_secreta)):
if letra == palavra_secreta[i]:
tela[i] = letra
def cria_exibicao():
x = ['_' for _ in range(len(palavra_secreta))]
return x
if __name__ == "__main__":
print('*********************************')
print('***Bem vindo ao jogo da Forca!***')
print('*********************************')
palavra_secreta = 'banana'
# palavra_secreta = input('PALAVRA SECRETA: ')
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment