Code Monkey home page Code Monkey logo

hang_man's People

Contributors

purplesingularity avatar

hang_man's Issues

Issues

Part 2

is_word_guessed

hang_man/hangman.py

Lines 64 to 67 in 3acdf65

if word_copy == let_copy:
return True
else:
return False

Це еквівалентно return word_copy == let_copy.

get_available_letters

hang_man/hangman.py

Lines 95 to 99 in 3acdf65

guess = set(letters_guessed)
let = set(string.ascii_lowercase)
dif = list(let.difference(guess))
dif.sort()
left = ''.join(dif)

Це явно можна написати простіше, наприклад: dif = l for l in string.ascii_lowercase if l not in letters_guesed. Так у вас принаймні тільки один раз будуть копіюватися значення.

Part 3

hang_man/hangman.py

Lines 143 to 144 in 3acdf65

if inp in letters_guessed or inp not in string.ascii_lowercase:
letters_tried.append(inp)

Ви перевіряєте letter_guessed, а додаєте у letters_tried. Через це ваша програма працює некоректно.

vow = {'a', 'i', 'e', 'y', 'o', 'u'}

Це порушує умову 3.D.6: y не рахується за голосну при розрахунку втрачених спроб.

if inp in letters_guessed or inp not in string.ascii_lowercase:

Спробуйте виводити текст у залежності від помилки, можливо ці дві умови варто розділити.

Part 4

match_with_gaps

hang_man/hangman.py

Lines 197 to 200 in 3acdf65

if my_word[i] != other_word[i] and my_word[i] != "_":
return False
elif my_word[i] == '_' and other_word[i] != '_' and other_word[i] in set_let:
return False

Ці умови можна спростити об'єднавши. Крім того, other_word[i] != '_' завжди True.

show_possible_matches

Іронічно, але ця функція не відповідає умові з 4.3В: вона не має нічого повертати, вона має відразу виводити. Її сигнатура має бути str -> None, а не str -> str.

hang_man/hangman.py

Lines 215 to 218 in 3acdf65

result = "Posible words: "
for i in wordlist:
if match_with_gaps(my_word,i):
result += i + " "

Так краще не робити: рядки є іммутабельними, тому на кожному присвоєнні створюється новий рядок, що тягне за собою виділення пам'яті і т.д. Простіше додавати усі слова до списку, а потім викликати ' '.join(result).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.