Created
August 20, 2016 00:42
-
-
Save thr0wn/72c062639ecca1eaa05b899d222b24a5 to your computer and use it in GitHub Desktop.
Jogo da forca
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
words = ['jamelao', 'rato-borrachudo', 'e_nois_que_voa_bruxao', 'olha_o_bicho_vindo_moleque'] | |
selectedWord = random.choice(words) | |
successes, errors = [], 0 | |
print("Jogo da forca") | |
while len(successes) < len(selectedWord) and errors < 2 * len(selectedWord): | |
c = input("palpite: ") | |
try: | |
if len(c) != 1: | |
raise Exception() | |
i = selectedWord.index(c) | |
successes.append(i) | |
except: | |
print("Errou. Você tem mais %d changes!" % (2 * len(selectedWord) - errors)) | |
errors += 1 | |
successWord = "" | |
for c in selectedWord: | |
index = selectedWord.index(c) | |
if index in successes: | |
successWord = successWord + c | |
else: | |
successWord = successWord + "_" | |
print(successWord + "\n") | |
if len(successes) == len(selectedWord): | |
print("Ganhou! Cê é o bichão mesmo ein?") | |
else: | |
print("Perdeu, vacilão!") | |
# TODO: corrigir condição de saída do while | |
# TODO: Vc acha isso saudável/correto? Acho... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment