Guest User

Untitled

a guest
Nov 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import sys
  4.  
  5. class pyall:
  6. def __init__(self):
  7. print("Hello")
  8.  
  9. def add(self,a,b):
  10. return a+b
  11.  
  12. def subt(self,a,b):
  13. return a-b
  14.  
  15. def mult(self,a,b):
  16. return a*b
  17.  
  18. def div(self,a,b):
  19. if b!=0:
  20. return a/b
  21. elif b==0:
  22. return "Divide by zero error."
  23.  
  24. def funSumlistAction(self, lists=[]):
  25. total=0
  26. for element in lists:
  27. total=total + int(element)
  28. return total
  29.  
  30. def process(self):
  31. str=["\n1.Add",
  32. "2.Subtract",
  33. "3.Multiplication",
  34. "4.Division",
  35. "5.Sum of integer list",
  36. "6.Type \"quit\" to quit"]
  37.  
  38. for name in str:
  39. print(name)
  40.  
  41. sys.stdout.write("Select: ")
  42.  
  43. varTakeInput=raw_input()
  44. if varTakeInput=="quit":
  45. exit()
  46.  
  47. varTakeInteger=int(varTakeInput)
  48. print(varTakeInput)
  49.  
  50. if varTakeInteger==1:
  51. varRes=self.add(9,5)
  52.  
  53. elif varTakeInteger==2:
  54. varRes=self.subt(9,5)
  55.  
  56. elif varTakeInteger==3:
  57. varRes=self.mult(5,9)
  58.  
  59. elif varTakeInteger==4:
  60. varRes=self.div(4/2)
  61.  
  62. elif varTakeInteger==5:
  63. sys.stdout.write("Enter a list of integer: ")
  64. varTakeList=[]
  65. varTakeList=raw_input()
  66. a=[]
  67. a=varTakeList.split(',')
  68. print a
  69. for x in a:
  70. x.strip()
  71. print a
  72.  
  73. varRes=self.funSumlistAction(a)
  74.  
  75. print("Result: ",varRes)
  76.  
  77.  
  78. if __name__ == "__main__":
  79. obj=pyall()
  80. while 1>0:
  81. obj.process()
  82.  
  83.  
  84. $python file.py
  85. Hello
  86.  
  87. 1.Add
  88. 2.Subtract
  89. 3.Multiplication
  90. 4.Division
  91. 5.Sum of integer list
  92. 6.Type "quit" to quit
  93. Select: 5
  94. 5
  95. Enter a list of integer: 5, 2, 2
  96. ['5', ' 2', ' 2']
  97. ['5', ' 2', ' 2']
  98. ('Result: ', 9)
Add Comment
Please, Sign In to add comment