From b441aa5dcfbdd1027a6f98bd78a28f89d540a444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Korbanek?= Date: Fri, 8 Mar 2019 21:03:38 +0000 Subject: [PATCH] =?UTF-8?q?Usu=C5=84=20'hangman.py'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hangman.py | 76 ------------------------------------------------------ 1 file changed, 76 deletions(-) delete mode 100644 hangman.py diff --git a/hangman.py b/hangman.py deleted file mode 100644 index 9ca175a..0000000 --- a/hangman.py +++ /dev/null @@ -1,76 +0,0 @@ - # hangman.py - -import random - -def get_secret_word(word_file="/usr/share/dict/words"): - with open(word_file) as f: - good_words = [] - for i in f: - i = i.strip() - if len(i) <= 6: - continue - if not i.isalpha(): - continue - if i[0].isupper(): - continue - good_words.append(i) - return random.choice(good_words) - -def get_masked_word(word_file): - mask_word="*" * len(word_file) - return mask_word - -def type_guess_word(word_file, guess_word, guessed_line): - if guess_word in word_file: - x = 0 - for i in word_file: - if i == guess_word: - guessed_line = guessed_line [0:x] + guess_word + guessed_line[x+1:] - x = x+1 - else: - print("Zly strzal") - print("-----------------------------") - return guessed_line - -def user_input(input=input): - letter = input("Podaj litere: ") - return letter - - -def n_main(): - print ("Witaj.") - s_word =(get_secret_word()) - #print(s_word) - guessed_line=(get_masked_word(s_word)) - print(get_masked_word(s_word)) - a =True - tries=10 - guess_word_list = [] - while a: - if guessed_line == s_word: - print("\nGratulacje, wygrales!") - break - print("----------------------------------------") - print("\nPozostalo prob = {}".format(tries)) - guess_word = user_input() - if guess_word in guess_word_list: - print("already guess") - continue - if guess_word.isdigit(): - print("Liczby nie sa dozwolone") - continue - if len(guess_word) != 1: - print("\n Dozwolone tylko pojedyncze litery!\n") - continue - guess_word_list.append(guess_word) - guessed_line = type_guess_word(s_word, guess_word,guessed_line) - print (guessed_line) - print ("Odgadnales ={}".format(guess_word_list)) - print("========================================") - tries = tries-1 - if (tries < 1): - a= False - print ("\n Nie udalo ci sie. Chodzilo o slowo {} \n\n".format(s_word)) - -if __name__ == "__main__": - n_main()