15.12.2022 Views

Python Eficaz

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

@quota.setter

def quota(self, amount):

delta = self.max_quota - amount

if amount == 0:

# Quota sendo reiniciada para um novo período

self.quota_consumed = 0

self.max_quota = 0

elif delta < 0:

# Quota sendo preenchida para um novo período

assert self.quota_consumed == 0

self.max_quota = amount

else:

# Quota sendo consumida durante o período

assert self.max_quota >= self.quota_consumed

self.quota_consumed += delta

Executando o programa de demonstração novamente, o mesmo dos exemplos

anteriores, obtemos os mesmos resultados.

bucket = Bucket(60)

print('Initial', bucket)

fill(bucket, 100)

print('Filled', bucket)

if deduct(bucket, 99):

print('Had 99 quota')

else:

print('Not enough for 99 quota')

print('Now', bucket)

if deduct(bucket, 3):

print('Had 3 quota')

else:

print('Not enough for 3 quota')

www.full-ebook.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!