Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

Minha forca

Só queria comentar que eu fiz um jogo da forca antes (sem precisar ler/escrever arquivos) e queria compartilhar aqui pq eu acho relevante que os meus colegas tenham uma ideia mais ampla de como fazer as coisas. PS: Ele funciona, mas falta fazer uns ajustes e adicionar alguns por exemplo, mas nada complicado, eg: fazer o boneco aparecer por partes, mostrar letras erradas, impedir inputs inválidas/repetidas, etc.

insira seu código aqui
from letter_counter import *
import random

zoo=['zebra','lion','bear','penguin']
secret_word=random.choice(zoo)
#secret_word=input()
letter=[]
z=0
for i in secret_word:
    letter.append(secret_word[z])
    z+=1

#print(letter)

output=[]
for i in letter:
    output.append('_ ')

print(''.join(output))

swlc=lc(''.join(letter),0,1)

hanged_man='''

      _______
     |/      |
     |      (_)
     |      \|/
     |       |
     |      / \\
     |
 ____|____
 '''

ptl=10
while True:
    inp=input() #get and store the input
    if inp=='0':
        break

    if inp in letter: #checks if the input is correct
        z=0
        for i in letter: #loops through the letters on the secret word
            if inp==letter[z]: #checks if the current item is the same as the input
                output[z]=inp+' ' #modify the output
            z+=1
        print('gotcha')
    else:
        print('wrong')
        ptl-=1
        if ptl==0:
            print('------GAME OVER------')
            print(hanged_man)
            break
    print(''.join(output))
    if output.count('_ ')==0:
        print('you won')
        break

input('do you want to play again?')
3 respostas

Olá Shinigami, muito boa a sua iniciativa de tentar melhorar o que é ensinado. Isso é uma maneira muito boa de fixar o que é aprendido.

solução!

Parabéns! Sempre bom colocar um pouco do seu conhecimento em cima do que foi apresentado como padrão. Dica, compartilha lá no seu github e vai criando um portfólio.

Obrigado Diego e Ronald, assim que eu fizer um github eu posto lá, e esqueci de compartilhar o lettter_counter que eu acabei nem usando, mas se alguém quiser vou deixar aqui também.

def lc(word,rl=0,rc=0):
    letter=[]
    count=[]
    z=0
    for i in word:
        x=word.count(word[z]) #counts the repetitions of an element
        if word[z] not in letter:  #avoids repetitions
            letter.append(word[z]) #adds the letter to the list
            count.append(x) #adds the number of repetitions
        z+=1
    if rl==0 and rc==0:
        print(letter,count,sep='\n')
    if rl==1:
        return letter
    if rc==1:
        return count

#lc('garoto')

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software