Zaktualizuj 'hangman.py'
This commit is contained in:
parent
880975c64e
commit
e3b1270c7a
24
hangman.py
24
hangman.py
@ -7,11 +7,11 @@ def get_secret_word(word_file="/usr/share/dict/words"):
|
|||||||
good_words = []
|
good_words = []
|
||||||
for i in f:
|
for i in f:
|
||||||
i = i.strip()
|
i = i.strip()
|
||||||
if len(i) <= 6: # No short words
|
if len(i) <= 6:
|
||||||
continue
|
continue
|
||||||
if not i.isalpha(): # No punctuation
|
if not i.isalpha():
|
||||||
continue
|
continue
|
||||||
if i[0].isupper(): # No proper nouns
|
if i[0].isupper():
|
||||||
continue
|
continue
|
||||||
good_words.append(i)
|
good_words.append(i)
|
||||||
return random.choice(good_words)
|
return random.choice(good_words)
|
||||||
@ -28,17 +28,17 @@ def type_guess_word(word_file, guess_word, guessed_line):
|
|||||||
guessed_line = guessed_line [0:x] + guess_word + guessed_line[x+1:]
|
guessed_line = guessed_line [0:x] + guess_word + guessed_line[x+1:]
|
||||||
x = x+1
|
x = x+1
|
||||||
else:
|
else:
|
||||||
print("Wrong guess")
|
print("Zły strzał")
|
||||||
print("-----------------------------")
|
print("-----------------------------")
|
||||||
return guessed_line
|
return guessed_line
|
||||||
|
|
||||||
def user_input(input=input):
|
def user_input(input=input):
|
||||||
letter = input("enter the chacracter=")
|
letter = input("Podaj literę: ")
|
||||||
return letter
|
return letter
|
||||||
|
|
||||||
|
|
||||||
def n_main():
|
def n_main():
|
||||||
print ("Welcome.")
|
print ("Witaj.")
|
||||||
s_word =(get_secret_word())
|
s_word =(get_secret_word())
|
||||||
#print(s_word)
|
#print(s_word)
|
||||||
guessed_line=(get_masked_word(s_word))
|
guessed_line=(get_masked_word(s_word))
|
||||||
@ -48,24 +48,24 @@ def n_main():
|
|||||||
guess_word_list = []
|
guess_word_list = []
|
||||||
while a:
|
while a:
|
||||||
if guessed_line == s_word:
|
if guessed_line == s_word:
|
||||||
print("\n\U0001F44D\U0001F44D\U0001F44D CONGRATULATION ..!! YOU WON THE GAME")
|
print("\nGratulacje, wygrałeś!")
|
||||||
break
|
break
|
||||||
print("----------------------------------------")
|
print("----------------------------------------")
|
||||||
print("\nTries left = {}".format(tries))
|
print("\nPozostało prób = {}".format(tries))
|
||||||
guess_word = user_input()
|
guess_word = user_input()
|
||||||
if guess_word in guess_word_list:
|
if guess_word in guess_word_list:
|
||||||
print("already guess")
|
print("already guess")
|
||||||
continue
|
continue
|
||||||
if guess_word.isdigit():
|
if guess_word.isdigit():
|
||||||
print("digits not allowed")
|
print("Liczby nie są dozwolone")
|
||||||
continue
|
continue
|
||||||
if len(guess_word) != 1:
|
if len(guess_word) != 1:
|
||||||
print("\n single char only...!!!\n")
|
print("\n Dozwolone tylko pojedyncze litery!\n")
|
||||||
continue
|
continue
|
||||||
guess_word_list.append(guess_word)
|
guess_word_list.append(guess_word)
|
||||||
guessed_line = type_guess_word(s_word, guess_word,guessed_line)
|
guessed_line = type_guess_word(s_word, guess_word,guessed_line)
|
||||||
print (guessed_line)
|
print (guessed_line)
|
||||||
print ("already guessed word ={}".format(guess_word_list))
|
print ("Odgadnąłeś ={}".format(guess_word_list))
|
||||||
print("========================================")
|
print("========================================")
|
||||||
tries = tries-1
|
tries = tries-1
|
||||||
if (tries < 1):
|
if (tries < 1):
|
||||||
|
Loading…
Reference in New Issue
Block a user