0
import random

list1 = ["chips", "banana", "cake", "wine", "cookie", "apple", "chocolate"]
random_word = random.choice(list1)
user_guesses = 0
guess_limit = 10
index = 0
guessleft = guess_limit - user_guesses
index_1 = random_word[index]
length = len(random_word)

for a in range(len(random_word)):
    print("_")

So the output of this loop will be underscores under eachother instead of them being after eachother like this _ _ _ _ _

How can i fix this?

2 Answers2

4

Change this:

print("_")

To this:

print("_", end="")

Or if you want them to have a space between them you can do it like this

print("_", end=" ")
Marko Borković
  • 1,884
  • 1
  • 7
  • 22
1

Instead of using

for a in range(len(random_word)):
    print("_")

you can use

print(*('_' for i in range(len(random_word))), sep=' ')

or

print(' '.join('_' * len(random_word)))
Riccardo Bucco
  • 13,980
  • 4
  • 22
  • 50