如何在使用 end=" " 的另一行下方打印一行

How do I print a line below another line that is using end=" "

所以基本上我正在尝试制作一个刽子手游戏,我的代码工作正常,但我对 end=" "

感到困惑
print("Welcome to hangman game!")

import random
words = ["facts", "air", "count", "wack"]
word = random.choice(words)
letters_guessed = []
guesses_left = 9
list(word)


while guesses_left > 0:
    print("The word contains {} letters".format(len(word)))
    for i in word:
        print("_", end=" ")

    user = input("Enter a letter --> ")    

这是我得到的输出:

Welcome to hangman game!
The word contains 3 letters
_ _ _ Enter a letter -->   

我想在“_ _ _”下方打印“输入字母 -->”。 我怎样才能做到这一点?这是我第一次使用 end=" " 所以是的

在那种情况下,您需要在 for 循环之后使用一个空的 print()

for i in word:
    print("_", end=" ")
print()

或者简单地说,使用 sep。此外,您需要为 sep:

提供 2 个参数
print("_"*len(word), sep=" ")

您可以在 input 提示中添加 \n

user = input("\nEnter a letter --> ") 
print("Welcome to hangman game!")

import random
words = ["facts", "air", "count", "wack"]
word = random.choice(words)
letters_guessed = []
guesses_left = 9
list(word)


while guesses_left > 0:
    print("The word contains {} letters".format(len(word)))
    for i in word:
        print("_", end=" ")

user = input("Enter a letter : ")

比较好看