LocalDogeCoder
LocalDogeCoder

Reputation: 83

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

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

Answers (3)

CFOP code
CFOP code

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

Scott Hunter
Scott Hunter

Reputation: 49893

You could add a \n to your input prompt:

user = input("\nEnter a letter --> ") 

Upvotes: 1

user15801675
user15801675

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

Related Questions