fork(1) download
  1. free_pc = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  2. daily_cash = 0
  3.  
  4.  
  5. class Player:
  6. price = 100 # за час
  7.  
  8. def __init__(self, nick, pc, hours):
  9. self.nick = nick
  10. self.pc = pc
  11. self.hours = hours
  12. self.cash = self.hours * Player.price
  13. global free_pc
  14. free_pc.remove(self.pc) # удаляем пк из списка доступных
  15. global daily_cash
  16. daily_cash += self.cash
  17.  
  18. def __len__(self):
  19. return self.hours
  20.  
  21. def __str__(self):
  22. return f'user {self.nick} on {self.pc} pc played {self.hours} hours'
  23.  
  24. def __del__(self):
  25. print(f'{self.pc} is free now')
  26. global free_pc
  27. free_pc.append(self.pc)
  28.  
  29.  
  30. p1 = Player('qwe', 4, 5)
  31. p2 = Player('asd', 2, 8)
  32. p3 = Player('zxc', 1, 1)
  33.  
  34. print('свободные компы: ', *free_pc)
  35. print(daily_cash)
  36. print(p3)
  37. del (p3)
  38. print(free_pc)
Success #stdin #stdout 0.02s 9416KB
stdin
Standard input is empty
stdout
свободные компы:  3 5 6 7 8 9 10
1400
user zxc on 1 pc played 1 hours
1 is free now
[3, 5, 6, 7, 8, 9, 10, 1]
4 is free now
2 is free now