Home > front end >  Exit If Statement
Exit If Statement

Time:01-14

I'm confused and stucked when im trying to quit/ continue in if statement

def checkQuota():
    with open("Discord\Test Field\config.json", "r ") as file:
        data = json.load(file)
        quota = data['guild setting']['daily quota']
        if quota > 0:

I want to check if quota is not 0 then continue for execution, but when quota equals to 0, I want it to stop at there. Anyone can help me?

CodePudding user response:

def checkQuota():
    with open(r"Discord\Test Field\config.json", "r ") as file:
        data = json.load(file)

    quota = data['guild setting']['daily quota']
    if quota == 0:
        # out of quota
        return

    # ...rest of the function below

CodePudding user response:

def checkQuota():
with open("Discord\Test Field\config.json", "r ") as file:
    data = json.load(file)
    item = data['guild setting']['daily quota']
    if item > 0:
        quotaChange = item - 1
        data['guild setting']['daily quota'] = quotaChange
        file.seek(0)
        json.dump(data, file, indent=4)
        file.truncate()
        
    else:
        print("Today's quota is 0, can't process command")

well i got it

  •  Tags:  
  • Related