fork(1) download
  1. class Cal(object):
  2. def __init__(self, v1, v2):
  3. if isinstance(v1, int):
  4. self.v1 = v1
  5. if isinstance(v2, int):
  6. self.v2 = v2
  7. def add(self):
  8. return self.v1+self.v2
  9. def subtract(self):
  10. return self.v1-self.v2
  11. def setV1(self, v):
  12. if isinstance(v, int):
  13. self.v1 = v
  14. def getV1(self):
  15. return self.v1
  16. c1 = Cal(10,10)
  17. print(c1.add())
  18. print(c1.subtract())
  19. c1.setV1('one')
  20. c1.v1 = 'one'
  21. c1.v2 = 30
  22. print(c1.add())
  23. print(c1.subtract())
Runtime error #stdin #stdout #stderr 0.02s 8736KB
stdin
Standard input is empty
stdout
20
0
stderr
Traceback (most recent call last):
  File "./prog.py", line 22, in <module>
  File "./prog.py", line 8, in add
TypeError: Can't convert 'int' object to str implicitly