Чтение PEP8 (https://www.python.org/dev/peps/pep-0008/#comments), Я вижу, что программисты должны «экономно использовать встроенные комментарии». Однако причина для этого не указана.
Интересно, почему. Мне действительно намного легчеПонимать программу, читая код с комментариями, чтобы я не прерывал комментарии, когда я на самом деле пытаюсь прочитать и понять код.
В лучшем случае, чтобы комментарии были такими, как мысделать в Word, соответствующий определенной точке кода, но видимый только на боковой панели. Я не знаю, есть ли IDE с такими функциями.
При этом, вопросы:
Есть ли техническая причина, например, потеря производительности, предпочитать делать аннотации в блоке, а не в строке?
Будут ли люди, читающие мой код, злитьсяо многих встроенных комментариях или это не имеет большого значения, при условии, что комментарии действительно полезны.
Есть ли IDE с лучшей средой для комментариев? Может быть, боковая панель, мaybe .txt файл, который связан с .py файлом и показывает эти комментарии через его пользовательский интерфейс.ИДК, что угодно.
Чтение PEP, документации по Python и попытка найти его.Нет полезных ответов.
(Извините, если слишком плохо. Вид новичка в Python 3.)
guessed_char = len(secret_word)*["_ "] # Defines varLIST of STRs, masked version of
# secret_word, and also the progression
# shown to the player
answer = len(secret_word)*[""] # Defines varLIST of STRs, that will be checked
# against secret_word (varSTR) through
# "".join(answer)
guessed_attempts = [] # Defines varLIST of STRs, that will store
# every letter guessed by the player.
enforcou = False # Defines varBOOL, turns True if attempts
# (varINT) reaches the limit. Ends the game
# with a loss.
acertou = False # Defines varBOOL, turns True if word is
# found by player. Ends the game with a win.
pontos = int(100) # Defines varINT, counts points that will be
# deduced at every failend attempt.Every
# change to this value must be followed by
# changes in other parts of this code
# Asks player for difficulty level
print("Qual nível de dificuldade?\n 1 - 3 tentativas\n 2- 5 tentativas\n 3 - 10 tentativas")
dificuldade = int(input())
if (dificuldade == 1):
max_attempts = 3 # Define varINT, total number of attempts
elif (dificuldade == 2):
max_attempts = 5 # Define varINT, total number of attempts
else:
print("Vamos jogar no fácil...")
max_attempts = 10 # Define varINT, total number of attempts
attempts = 1 # Define varINT, counts the number of attempts
print("".join(guessed_char)) # Prints the masked version of secret_word
# (varSTR) that the player is trying to guess
while (not enforcou and not acertou): # Conditions for ending the game.
print(f"Tentativa {attempts} de {max_attempts}") # Tells player the attempt number
guess = input("Qual letra? ").lower() # Asks for a guess (varSTR)
guessed_attempts.append(guess) # Adds the guess to the guess' storage
if (guess in secret_word): # If the guess is correct
index = 0 # Defines varINT for storing indexes
for char in secret_word.lower(): # iterate through every character in
# secret_word (varSTR)
if (guess == char): # If the guess matches the character
guessed_char[index] = f"{guess} " # Replaces dummy "_ " in
# guesed_char (varLIST)
# revealling guessed characters
# in the masked progresion shown
# to the player
answer[index] = f"{guess}" # Replaces dummy with answer
print(f"Encontrei a letra {char} na posiçao {index}") # Prints that something was correct
print("".join(guessed_char)) # Prints the update masked word
pontos += round(100/max_attempts) # Adds points
if("".join(answer) == secret_word): # Checks if the player won
acertou = True # End while cicle if player won
print(f"Você ganhou! A palavra era '{secret_word}'!") #Prints message telling player he/she won
index += 1 # Adds 1 to varINT index, so everything is on track
else: # If guess is not correct
pontos -= round(100/max_attempts) # Subtracts points
print("Que pena, você errou...") #Tells player he missed
print("".join(guessed_char)) # Print masked word
# Tells player the guesses he already tried, with correct grammar for linstings in portuguese
print("Você já tentou as letras ", ", ".join(str(e) for e in guessed_attempts[:-1]), " e ", guessed_attempts[-1], ".", sep="")
attempts += 1 # Adds 1 to varINT attempts, so the game get closer to end due to loss
enforcou = attempts == max_attempts+1 # Defines coditions for losing the game
if (enforcou): # If losing conditions are met
print(f"Que pena, você perdeu... A palavra era '{secret_word}'...") # Print loss message and the word
print(f"Você fez {pontos} pontos.") # Prints the number of points, regardless of winning or losing.
print ("Fim do jogo") # Tells the player the game ended.