-2

look at my simple code, i just want when user put correct or wrong answer then above score in print statement update automatic.

score = 10
print("="*50 + "[ Your Score: "+ str(score) +" ]" + "="*50)

inputs = raw_input("5 + 5 = ")
if inputs == '10':
    score += 10
    # then i want to update the above print statement

result:

=======================[ Your Score: 10 ]=====================
5 + 5 = 10

3 Answers3

1

You can't update an already printed output.

You will have to clear your output and reprint with the new score. Have a look at this question

CobyC
  • 2,058
  • 1
  • 18
  • 24
0

you can use While loop.

   score=10
   inputs = raw_input("5 + 5 = ")
   while(input==10):
       score+=10
       print("="*50 + "[ Your Score: "+ str(score) +" ]" + "="*50)
0
def update(score):
    print("="*50 + "[ Your Score: "+ str(score) +" ]" + "="*50)

score = 10
update(score)
inputs=input("5 + 5 = ")
if inputs == '10':
    score += 10
    update(score)

Just try this.

Rohan Mathur
  • 1
  • 1
  • 2