簡體   English   中英

我只想更新我的 python 代碼中的第一個打印語句

[英]I just want to update first print statment in my python code

看看我的簡單代碼,我只想當用戶輸入正確或錯誤答案時,打印語句自動更新高於分數。

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

結果:

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

您無法更新已打印的 output。

您必須清除您的 output 並重新打印新的分數。 看看這個問題

您可以使用 While 循環。

   score=10
   inputs = raw_input("5 + 5 = ")
   while(input==10):
       score+=10
       print("="*50 + "[ Your Score: "+ str(score) +" ]" + "="*50)
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)

試試這個。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM