我该如何为此添加一个计数器

问题描述 投票:-2回答:1

我想为这段代码添加一个计数器,所以每次打印出ligma这个词都会计算在屏幕上打印ligma的次数

import winsound
import time
from threading import Thread

def play_sound():
    for _ in range(10):
        winsound.PlaySound("dank", winsound.SND_ALIAS)
        time.sleep(2.5)

thread = Thread(target=play_sound)
thread.start()

while True:
    print ('ligma')
    time.sleep(1.5)
python python-3.x syntax
1个回答
1
投票
count = 0
while True:
    print ('ligma')
    count += 1
    time.sleep(1.5)
© www.soinside.com 2019 - 2024. All rights reserved.