Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import sys
- class pyall:
- def __init__(self):
- print("Hello")
- def add(self,a,b):
- return a+b
- def subt(self,a,b):
- return a-b
- def mult(self,a,b):
- return a*b
- def div(self,a,b):
- if b!=0:
- return a/b
- elif b==0:
- return "Divide by zero error."
- def funSumlistAction(self, lists=[]):
- total=0
- for element in lists:
- total=total + int(element)
- return total
- def process(self):
- str=["\n1.Add",
- "2.Subtract",
- "3.Multiplication",
- "4.Division",
- "5.Sum of integer list",
- "6.Type \"quit\" to quit"]
- for name in str:
- print(name)
- sys.stdout.write("Select: ")
- varTakeInput=raw_input()
- if varTakeInput=="quit":
- exit()
- varTakeInteger=int(varTakeInput)
- print(varTakeInput)
- if varTakeInteger==1:
- varRes=self.add(9,5)
- elif varTakeInteger==2:
- varRes=self.subt(9,5)
- elif varTakeInteger==3:
- varRes=self.mult(5,9)
- elif varTakeInteger==4:
- varRes=self.div(4/2)
- elif varTakeInteger==5:
- sys.stdout.write("Enter a list of integer: ")
- varTakeList=[]
- varTakeList=raw_input()
- a=[]
- a=varTakeList.split(',')
- print a
- for x in a:
- x.strip()
- print a
- varRes=self.funSumlistAction(a)
- print("Result: ",varRes)
- if __name__ == "__main__":
- obj=pyall()
- while 1>0:
- obj.process()
- $python file.py
- Hello
- 1.Add
- 2.Subtract
- 3.Multiplication
- 4.Division
- 5.Sum of integer list
- 6.Type "quit" to quit
- Select: 5
- 5
- Enter a list of integer: 5, 2, 2
- ['5', ' 2', ' 2']
- ['5', ' 2', ' 2']
- ('Result: ', 9)
Add Comment
Please, Sign In to add comment