Я очень новый программист (начал меньше месяца назад). Мне действительно нужна помощь с этим. Извините, если это немного долго ... Как это работает, мои догадки теряются каждый раз, когда я что-то не так (довольно очевидно). Или все-таки предполагается.
Это программа, которую я создал в качестве прототипа для проекта Hangman. Как только я пойму это правильно, я смогу попробовать более крупный проект. Скажите мне, если приведенная выше полная команда работает по-другому для вас, или если у вас есть какие-либо предложения относительно того, как сделать ее короче или лучше, или мне пока слишком рано пытаться выполнить такой большой проект. Спасибо!
import random
player_name = input("What is your name? ")
print("Good luck, " + player_name + "!")
words = ["program", "giraffe", "python", "lesson", "rainbows", "unicorns", "keys", "exercise"]
guess = " "
repeat = True
word = random.choice(words)
guesses = int(len(word))
while repeat is True:
print("The word is " + str(len(word)) + " characters long.")
guess = input("Enter your guess: ")
if guess != word:
guesses -= 1
print("Incorrect")
print("Try again")
elif guess == word:
print("Good job!")
print(str.capitalize(word) + " is the right answer!")
repeat = input("Do you want to play again? (input Yes/No)")
if repeat == "Yes" or "yes":
word = random.choice(words)
repeat = True
elif repeat == "No" or "no":
print("Better luck next time!")
repeat = False
if guesses == 1:
print("You only have one chance left.")
if guesses <= 0:
print("You lose...")
repeat = input("Do you want to play again? (input Yes/No)")
if repeat == "Yes" or "yes":
repeat = True
elif repeat == "No" or "no":
print("Better luck next time!")
repeat = False