Advertisement
makispaiktis

Codewars - Playing with digits

Aug 10th, 2021 (edited)
1,608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. def dig_pow(n, p):
  2.     print("n = " + str(n) + ", p = " + str(p))
  3.     nStr = str(n)
  4.     digits = [int(nStr[i]) for i in range(len(nStr))]
  5.     # Checking
  6.     flag = False
  7.     number2 = 0
  8.     for i in range(1, len(digits) + 1):
  9.         number2 += digits[i-1] ** (p+i-1)
  10.     print("number2 = " + str(number2))
  11.     if number2 % n != 0:
  12.         print("number2 % n != 0")
  13.         return -1
  14.     else:
  15.         result = int(number2 / n)
  16.         print("number2 / n = " + str(result))
  17.         return result
  18.  
  19. # MAIN FUNCTION
  20. print(dig_pow(89, 1))
  21. print()
  22. print(dig_pow(92, 1))
  23. print()
  24. print(dig_pow(256, 2))
  25. print()
  26. print(dig_pow(695, 2))
  27. print()
  28. print(dig_pow(46288, 3))
  29. print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement