Python Day 19: Interfaces




The AdvancedArithmetic interface and the method declaration for the abstract divisorSum(n) method are provided for you in the editor below.

Complete the implementation of Calculator class, which implements the AdvancedArithmetic interface. The implementation for the divisorSum(n) method must return the sum of all divisors of n.

-HackerRank solution



  1. class AdvancedArithmetic(object):
  2. def divisorSum(n):
  3. raise NotImplementedError
  4. class Calculator(AdvancedArithmetic):
  5. def divisorSum(self, n):
  6. #pass
  7. x = []
  8. for i in range(1, n+1):
  9. if n % i == 0:
  10. x.append(i)
  11. else:
  12. pass
  13. return sum(x)
  14. n = int(input())
  15. my_calculator = Calculator()
  16. s = my_calculator.divisorSum(n)
  17. print("I implemented: " + type(my_calculator).__bases__[0].__name__)
  18. print(s)
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube