You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
705 B
32 lines
705 B
12 months ago
|
import threading
|
||
|
|
||
|
class Cuenta:
|
||
|
|
||
|
def __init__(self, saldoInicial):
|
||
|
self.saldo = saldoInicial
|
||
|
self.lock = threading.Lock()
|
||
|
|
||
|
def depositar(self, cantidad):
|
||
|
self.lock.acquire()
|
||
|
self.saldo += cantidad
|
||
|
self.printSaldo()
|
||
|
self.lock.release()
|
||
|
|
||
|
def extraer(self, cantidad):
|
||
|
self.lock.acquire()
|
||
|
if self.saldo < cantidad:
|
||
|
print("No hay saldo suficiente")
|
||
|
return False
|
||
|
self.saldo -= cantidad
|
||
|
self.printSaldo()
|
||
|
self.lock.release()
|
||
|
|
||
|
def printSaldo(self):
|
||
|
print("El saldo es: ", self.saldo)
|
||
|
|
||
|
|
||
|
|
||
|
cuenta = Cuenta(1000)
|
||
|
cuenta.printSaldo()
|
||
|
for i in range(10):
|
||
|
cuenta.extraer(100)
|