Advertisement
Guest User

Michas Hangman

a guest
Oct 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. import os
  2. import random
  3.  
  4. anzVersuche = 10
  5. versuch = 0
  6. gefunden = 0
  7.  
  8.  
  9. def getWords():
  10.     wortliste = []
  11.     file = open('wortliste.txt')
  12.  
  13.     for word in file:
  14.         wortliste.append(word)
  15.  
  16.     # get random word
  17.  
  18.     gesWort = wortliste[random.randrange(0, len(wortliste), 1)]
  19.  
  20.     return gesWort
  21.  
  22.  
  23. gesWort = getWords()
  24. gezWort = ['*'] * (len(gesWort) - 1)
  25.  
  26. print(gezWort)
  27. while versuch < anzVersuche:
  28.     eingabe = input("Geben sie ihren Buchstaben ein: ")
  29.     index = 0
  30.     for buchstabe in gesWort:
  31.         if (eingabe == buchstabe):
  32.             gezWort[index] = eingabe
  33.             gefunden += 1
  34.  
  35.         index += 1
  36.  
  37.     if (gefunden == len(gesWort) - 1):
  38.         print(gezWort)
  39.         print("GEWONNEN, das gesuchte Wort war", gesWort)
  40.         break
  41.  
  42.     versuch += 1
  43.  
  44.     os.system('cls')
  45.     print('Noch ', anzVersuche - versuch, " Versuche übrig")
  46.     print(gezWort)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement