Advertisement
Guest User

Ahorcado

a guest
Sep 19th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. """
  2. @author: Mariano
  3. """
  4.  
  5. word = input("Palabra: ").upper()
  6. wordList = list(word)
  7.  
  8. print("\nCantidad de letras: ", len(wordList))
  9.  
  10. inLetter = []
  11. for i in wordList:
  12. inLetter.append("_")
  13.  
  14. def Hangman(letter):
  15. global aciertos
  16. for i in wordList:
  17. if letter == i:
  18. inLetter.insert(wordList.index(i), letter) #ingresa en la lista
  19. inLetter.pop(wordList.index(i)+1) #se borra el "_"
  20. index1 = wordList.index(letter) #modifica la primer ocurrencia
  21. wordList[index1] = 0
  22. aciertos += 1
  23. return inLetter
  24.  
  25. intentos = 5
  26. aciertos = 0
  27. while intentos > 0 and aciertos < len(wordList):
  28. letter = input("Letra: ").upper()
  29. inWord = letter in word
  30. if inWord == False: #si la letra no esta en la palabra
  31. intentos -= 1
  32. print(f"Te quedan {intentos} intento(s)")
  33. if intentos == 0: #fin del juego
  34. print("\nPerdiste")
  35. elif inWord == True: #si la letra esta en la palabra
  36. if wordList.count(letter) == 1: #y aparece una sola vez
  37. print(Hangman(letter))
  38. elif wordList.count(letter) > 0: #o aparece mas de una vez
  39. print(Hangman(letter))
  40. elif letter in inLetter: #o si ya usaste la letra
  41. print("Ya usaste esa palabra")
  42.  
  43. if aciertos == len(wordList):
  44. print("\nGanaste!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement