-1

If I for example had a code like this:

score = 0
loop = true
while loop:
    score = (score) + 1
    print(score)

But I wanted to only print the new value of score instead of a long list of previous values aswell how would I do that?

martineau
  • 119,623
  • 25
  • 170
  • 301
  • 7
    Don't put it in the loop? – Scott Hunter Mar 24 '22 at 18:22
  • 3
    Does this answer your question? [Replace console output in Python](https://stackoverflow.com/questions/6169217/replace-console-output-in-python) Of course, if the ultimate purpose is to produce progress bar, there are convenient packages to display progress bar – buran Mar 24 '22 at 18:24
  • Note that `loop = true` is invalid (`true` is undefined name). And braces are redundant in `score = (score) + 1` – buran Mar 24 '22 at 18:28

1 Answers1

0
print("Something", end='\r')

This way, any successive output will overwrite this one.

score = 0
while True:
    score += 1
    print(f"{score}  ", end='\r')

Notice that in Python true is undefined, and unlike C, C++, JavaScript and some other languages, True and False are uppercase.

FLAK-ZOSO
  • 3,873
  • 4
  • 8
  • 28