Advertisement
Guest User

Ahorcado

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