Noah Hammer
Noah Hammer

Reputation: 1

Print on one line in python Window

I'm not sure how to get multiple outputs from a for loop to print on the same line in a window. I'm using the built in Window function from uagame with python3.x. Here's what the code looks like:

for char in a_word:
 if char in user_guess:
  window.draw_string(char+" ",x, y)
 else:
  window.draw_string('_ ',x, y)
 y = y + font_height

This keeps displaying as:

_
_
_
_

And I want it to print as

_ _ _ _

Any idea how to get each character or _ to display on one line? This is for a WordPuzzle/Hangman type game.

Upvotes: 0

Views: 169

Answers (2)

vrk
vrk

Reputation: 56

Define a empty list and append your characters then print all at once

a=[]   
    for char in a_word:
         if char in user_guess:
              a.append(char)
         else:
              a.append(char)
    print(a,end=",")
    y = y + font_height

Upvotes: 0

Chetan_Vasudevan
Chetan_Vasudevan

Reputation: 2414

Use this as a example, and hopefully you will implement the same to your code.

    for i in range(1,10):
        print(i,end=",")
     print()

The output looks like

1,2,3,4,5,6,7,8,9,

Upvotes: 1

Related Questions