Reputation: 83
So basically I'm trying to make a hangman game, and my code works fine but I'm getting confused with the 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 --> ")
This is the output I get:
Welcome to hangman game!
The word contains 3 letters
_ _ _ Enter a letter -->
I want to print "Enter a letter --> " below the "_ _ _". How can I do that? This is my first time using end=" " so yeah
Upvotes: 0
Views: 957
Reputation: 1
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 : ")
It is more good looking
Upvotes: 0
Reputation: 49893
You could add a \n
to your input
prompt:
user = input("\nEnter a letter --> ")
Upvotes: 1
Reputation:
In that case, you need to use an empty print()
after the for
loop:
for i in word:
print("_", end=" ")
print()
Or simply, use sep
. Also, you need to have 2 arguments for sep:
print("_"*len(word), sep=" ")
Upvotes: 2