Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. class InputObject:
  2.    
  3.     def __init__(self, name):
  4.         self.name = name
  5.  
  6.  
  7. class Operation(InputObject):
  8.     """Operation class"""
  9.  
  10.    
  11.  
  12.     def __init__(self,oper ,lhs, rhs):
  13.  
  14.         self.oper = oper.lower()
  15.         self.lhs = lhs
  16.         self.rhs = rhs
  17.  
  18.  
  19.    
  20.          
  21.  
  22.  
  23.        
  24.     def executeOperation(self):
  25.         print("printar oper: ")
  26.         print(self.oper)
  27.         def addition(lhs, rhs):
  28.             print("inne i add")
  29.             lhs.value = lhs.value+rhs.value
  30.        
  31.  
  32.         def subtraction(lhs, rhs):
  33.             print("inne i sub")
  34.             lhs.value = lhs.value-rhs.value
  35.        
  36.  
  37.         def multiplication(lhs, rhs):
  38.             print("inne i mult")
  39.             lhs.value = lhs.value*rhs.value
  40.  
  41.         if (self.oper == "add"):
  42.             addition(self.lhs, self.rhs)
  43.         elif (self.oper == "minus"):
  44.             subtraction(self.lhs, self.rhs)
  45.         elif (self.oper == "mult"):
  46.             multiplication(self.lhs, self.rhs)
  47.         else:
  48.             print("ogiltid operation")
  49.             pass
  50.  
  51.            
  52.    
  53.  
  54.  
  55.    
  56.    
  57.  
  58.  
  59.  
  60.  
  61. class Value(InputObject):
  62.     """ value class"""
  63.     def __init__(self, name):
  64.  
  65.         #if (isinstance(float(name),float)):
  66.         if (name.isdigit() or name.isdecimal()):
  67.  
  68.             self.name = name
  69.             self.value = float(name) #fixa rätt med decimaler sen, fråga ante
  70.  
  71.         else:
  72.             self.name = name
  73.             self.value = 0
  74.  
  75.  
  76. class Register(InputObject):
  77.     """Register class"""
  78.     def __init__(self, name):
  79.  
  80.         self.name = name
  81.         self.value = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement