SHARE
TWEET

Untitled

a guest Dec 8th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '''
  2.  
  3.                             Online Python Compiler.
  4.                 Code, Compile, Run and Debug python program online.
  5. Write your code in this editor and press "Run" button to execute it.
  6.  
  7. '''
  8.  
  9. from inspect import *
  10.  
  11. class Money:
  12.  
  13.     def __init__(self, money):
  14.         self.money = money
  15.  
  16.     def __get__(self, instance, owner):
  17.         if self.money in instance.__dict__.keys():
  18.             return str(instance.__dict__[self.money]) + \
  19.             ' ' + str(self.money).upper()
  20.         else:
  21.             return str(instance.__class__.__name__) + \
  22.             ' object currently has no attribute "' \
  23.             + str(self.money) + '".'
  24.            
  25.     def __set__(self, instance, value):
  26.         """Set action."""
  27.         if self.money not in instance.__dict__.keys():
  28.             instance.__dict__[self.money] = value
  29.         else:
  30.             if value > 0:
  31.                 instance.__dict__[self.money] += value
  32.                 print(str(value) + ' ' + str(self.money).upper() + \
  33.                 ' was putted into your wallet.')
  34.  
  35.     def __delete__(self, instance):
  36.         del instance.__dict__[self.money]
  37.         print('Your ' + str(self.money).upper() + \
  38.         ' money account was closed.')
  39.        
  40.        
  41. class Wallet:
  42.  
  43.     __attributes = {'usd', 'eur', 'uah', 'gbp', 'chf', 'ownerName', 'ownerSurname'}
  44.  
  45.     def __init__(self, usd=float(), eur=float(), uah=float(),
  46.         name=str(), surname=str()):
  47.         self.ownerName = name
  48.         self.ownerSurname = surname
  49.         self.usd = usd
  50.         self.eur = eur
  51.         self.uah = uah
  52.  
  53.     usd = Money('usd')
  54.     eur = Money('eur')
  55.     uah = Money('uah')
  56.    
  57.     def __getattr__(self, item):
  58.         if item not in self.__dict__:
  59.             return str(self.__class__.__name__) + \
  60.             ' object currently has no attribute "' \
  61.             + str(item) + '"!'
  62.        
  63.     def __getattribute__(self, item):
  64.         return object.__getattribute__(self, item)
  65.    
  66.     def __setattr__(self, key, value):
  67.         if key not in self.__dict__:
  68.             if key in Wallet.__attributes:
  69.                 self.__dict__[str(key)] = value
  70.                 print('Attribute "' + str(key) + \
  71.                 '" was added to the object structure.')
  72.                 print('Attribute "' + str(key) + \
  73.                 '" was assigned with value ' + \
  74.                 str(value) + '!')
  75.             else:
  76.                 print('Attribute "' + str(key) + \
  77.                 '" cannot be added to the object structure.')
  78.         else:
  79.             if value > 0:
  80.                 self.__dict__[key] += value
  81.                 print('Attribute "' + str(key) + \
  82.                 '" was assigned with value ' \
  83.                 + str(value) + '!')
  84.  
  85.     def __delattr__(self, item):
  86.         del self.__dict__[item]
  87.         print('Attribute "' + str(item) + \
  88.         '" was removed form object structure.')
  89.  
  90. class PremiumWallet(Wallet):
  91.     def __init__(self, usd=float(), eur=float(), uah=float(),
  92.     gbp=float(), name=str(), surname=str()):
  93.         usd = usd + 100
  94.         eur = eur + 100
  95.         uah = uah + 1000
  96.         super().__init__(usd=usd, eur=eur, uah=uah,
  97.         name=name, surname=surname)
  98.         self.gbp = gbp + 100
  99.  
  100.     gbp = Money('gbp')
  101.  
  102. pw = PremiumWallet(usd=12.45, eur=45.24, uah=67.72, gbp=29.34, name='John', surname='Smith')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top