为什么我会有python错误unindent不匹配任何外部缩进级别错误

2024-10-02 00:28:20 发布

您现在位置:Python中文网/ 问答频道 /正文

from TikTokApi import TikTokApi 
import time 
import os
import random 

api = TikTokApi()

def getLikeCount():
    tiktoks = api.byUsername('user', count=1)
    for tiktok in tiktoks:
        likeCount = tiktok["stats"]["diggCount"]
        shareCount = tiktok["stats"]["shareCount"]
        commentCount = tiktok["stats"]["commentcount"]
        followCount = tiktok["authorStats"]["followerCount"]
        return (likeCount,shareCount,commentCount,followCount)

def fag():
    os.system("afplay -/desktop/tiktok/fag.mp3 ")


def update():
    initLikeCount = 0
    while True:
        results = getLikeCount()
        currentNumLikes = results[0]
        print("sleep time")
        time.sleep(5)

        if currentNumLikes > initLikeCount:
            newLikes = currentNumLikes - initLikeCount
            initLikeCount = currentNumLikes
            print("new like count = ",newLikes)
            for x in range(newLikes):
                print("now playing this Fag.mp3",x)
                time.sleep(random.randint(0,3))
                fag()
           else()
            print("no new likes ):")
update()
#getLikeCount() 

为什么会发生这种情况?我正在制作一个tiktok机器人,每次我得到一个类似于我得到一个噪音的游戏(顺便说一句,我在ubuntu上,但这也发生在windows上)


Tags: importtimeosdefstatssleepprinttiktok
2条回答

else语句与if语句不对齐

顺便说一句,下次使用ctrl-K在StackOverflow中对齐代码

函数getLikeCountupdate中有几个小错误

def getLikeCount():
    tiktoks = api.byUsername('user', count=1)
    for tiktok in tiktoks:
        likeCount = tiktok["stats"]["diggCount"]
        shareCount = tiktok["stats"]["shareCount"]
        commentCount = tiktok["stats"]["commentcount"]
        followCount = tiktok["authorStats"]["followerCount"]
    return (likeCount,shareCount,commentCount,followCount) # indentation corrected

def update():
    initLikeCount = 0
    while True:
        results = getLikeCount()
        currentNumLikes = results[0]
        print("sleep time")
        time.sleep(5)

        if currentNumLikes > initLikeCount:
            newLikes = currentNumLikes - initLikeCount
            initLikeCount = currentNumLikes
            print("new like count = ",newLikes)
            for x in range(newLikes):
                print("now playing this Fag.mp3",x)
                time.sleep(random.randint(0,3))
                fag()
        #  else() <- your code
        else: # indentation, brackets and colon corrected
            print("no new likes ):")

相关问题 更多 >

    热门问题