-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?

3
  • 7
    Don't put it in the loop? Commented Mar 24, 2022 at 18:22
  • 3
    Does this answer your question? Replace console output in Python Of course, if the ultimate purpose is to produce progress bar, there are convenient packages to display progress bar Commented Mar 24, 2022 at 18:24
  • Note that loop = true is invalid (true is undefined name). And braces are redundant in score = (score) + 1 Commented Mar 24, 2022 at 18:28

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.