import randomlist1 = ["chips", "banana", "cake", "wine", "cookie", "apple", "chocolate"]random_word = random.choice(list1)user_guesses = 0guess_limit = 10index = 0guessleft = guess_limit - user_guessesindex_1 = random_word[index]length = len(random_word)for a in range(len(random_word)): print("_")所以这个循环的输出将在彼此下面加上下划线,而不是像这样在彼此后面加上下划线 _ _ _ _我怎样才能解决这个问题?
2 回答

慕桂英3389331
TA贡献2036条经验 获得超8个赞
改变这个:
print("_")
对此:
print("_", end="")
或者如果你想让它们之间有一个空间,你可以这样做
print("_", end=" ")

qq_笑_17
TA贡献1818条经验 获得超7个赞
而不是使用
for a in range(len(random_word)): print("_")
您可以使用
print(*('_' for i in range(len(random_word))), sep=' ')
或者
print(' '.join('_' * len(random_word)))
添加回答
举报
0/150
提交
取消