Guest User

Untitled

a guest
Dec 15th, 2019
69
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import sys
  3.  
  4. a, b = int(input()), int(input())
  5. if a >= b and a > 9:
  6. c = a // b
  7. r = []
  8. m = list(str(a))
  9. pos = [0]
  10. length = len(m)
  11. ostatok = a
  12. z = 0
  13. while ostatok >= b:
  14. k = m[0]
  15. i = 1
  16. z = 0
  17. while int(k) < b and i != len(m):
  18. if int(k) == 0:
  19. z += 1
  20. k += m[i]
  21. i += 1
  22. m = [s for s in str(int(k) % b) if int(k) % b != 0] + m[i:]
  23. while len(m) != 0 and m[0] == '0':
  24. m = m[1:]
  25. pos.append(length - len(m))
  26. r.append(int(k))
  27. r.append(b * (int(k) // b))
  28. if len(m) != 0:
  29. ostatok = int(''.join(m))
  30. else:
  31. ostatok = 0
  32. pos[-1] = length - len(str(ostatok))
  33. if len(pos) > 1:
  34. pos[-2] += z
  35. r.append(ostatok)
  36. a = str(a)
  37. b = str(b)
  38. c = str(c)
  39. r = list(map(str, r))
  40. print(a + ' |' + b)
  41. true = [(pos[0], r[0], r[1])]
  42. j = 2
  43. for i in range(1, len(pos) - 1):
  44. true.append((pos[i], r[j], r[j + 1]))
  45. j += 2
  46. true.append((pos[-1], r[-1]))
  47. s = ' ' * (len(true[0][1]) - len(true[0][2])) + true[0][2]
  48. print(s + ' ' * (len(a) - len(s)) + ' +' + '-' * max(len(c), len(b)))
  49. s = true[1][0] + len(true[1][1])
  50. print('-' * s + ' ' * (len(a) - s) + ' |' + str(c))
  51. for i in range(1, len(true) - 1):
  52. p1 = true[i][0]
  53. p2 = true[i][0] + len(true[i][1]) - len(true[i][2])
  54. p3 = true[i + 1][0] - true[i][0] + len(true[i + 1][1])
  55. print(' ' * p1 + true[i][1])
  56. print(' ' * p2 + true[i][2])
  57. print(' ' * p1 + '-' * p3)
  58. print(' ' * true[-1][0] + true[-1][1])
  59.  
  60. else:
  61. if a < b:
  62. a, b = str(a), str(b)
  63. print(a + ' |' + b)
  64. print(' ' * len(a) + ' +' + '-' * len(b))
  65. print(' ' * len(a) + ' |' + '0')
  66. else:
  67. print(str(a) + ' |' + str(b))
  68. print(str(a // b * b) + ' +' + len(str(b)) * '-')
  69. print('- |' + str(a // b))
  70. print(str(a % b))
RAW Paste Data