-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforca.py
More file actions
58 lines (42 loc) · 1.26 KB
/
forca.py
File metadata and controls
58 lines (42 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from random import choice
from time import sleep
def escolha_palavra(palavras : str) -> str:
arquivo = open("palavras.txt", "r")
palavras = []
for linha in arquivo:
linha = linha.strip()
palavras.append(linha)
arquivo.close()
return choice(palavras)
def forca(palavra: str, letras: str) -> str:
erros = 0
acertou = False
enforcou = False
while not enforcou and not acertou:
chute = str(input("\nInforme uma letra: "))
chute = chute.strip().upper()
if chute in palavra:
index = 0
for letra in palavra:
if chute == letra:
letras[index] = letra
index += 1
else:
erros += 1
print(erros)
print(letras)
if erros == 5:
print("Você Perdeu!!")
print(f"A palavra correta é {palavra}")
enforcou = True
elif "_" not in letras:
print("Parabens!! Você acertou.")
acertou = True
def game():
print("*" *27)
print("****** JOGO DA FORCA ******")
print("*" *27)
palavra = escolha_palavra(palavras=str).upper()
letras = ["_" for letra in palavra]
forca(palavra, letras)
sleep(1)