Advertisement
Ahmed-_-Taha

sol

Aug 5th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. class Calculator(object):
  2.     total = []
  3.     everything = 0
  4.    
  5.     def __init__(self):
  6.         self.a = int(input("Enter a number: "))
  7.         self.b = int(input("Enter a number: "))
  8.         self.sum = sum
  9.         self.res = 0
  10.         self.rlist =[]
  11.        
  12.  
  13.     def add(self):
  14.         self.sum = self.a + self.b
  15.         print(self.sum)
  16.         self.total.append(self.sum)
  17.         self.everything = self.everything + self.sum
  18.         print(self.total)
  19.         print(self.everything)
  20.     def subtract(self):
  21.         self.sum = self.a - self.b
  22.         print(self.sum)
  23.         self.total.append(self.sum)
  24.         print(self.total)
  25.     def multiply(self):
  26.         self.sum = self.a * self.b
  27.         print(self.sum)
  28.         self.total.append(self.sum)
  29.         print(self.total)
  30.     def divide(self):
  31.         self.sum = self.a / self.b
  32.         print(self.sum)
  33.         self.total.append(self.sum)
  34.         print(self.total)
  35.     def totalres(self):
  36.         for i in self.total:
  37.             self.res += i
  38.             self.rlist.append(self.res)
  39.         print("Add:",self.rlist)
  40.  
  41. opp = 0
  42. while opp != "0":
  43.     calc1 = Calculator()
  44.     opp = input("Please enter 1 to ADD, 2 to SUBTRACT, 3 to MULTIPLY, 4 to DIVIDE: ")
  45.     if opp == "1":
  46.         calc1.add()
  47.        
  48.     elif opp == "2":
  49.         calc1.subtract()
  50.        
  51.     elif opp == "3":
  52.         calc1.multiply()
  53.        
  54.     elif opp == "4":
  55.         calc1.divide()
  56.     calc1.totalres()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement