Last active
September 2, 2025 19:33
-
-
Save ValeryVerkhoturov/faa8c7054061d644a07a52827cd6c7f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| from decimal import Decimal, getcontext | |
| getcontext().prec = 7 | |
| def split_amount_with_error(total_amount, parts=10, error_percent=10): | |
| total_amount = Decimal(str(total_amount)) | |
| error_fraction = Decimal(str(error_percent)) / Decimal('100') | |
| base_part = total_amount / Decimal(str(parts)) | |
| parts_list = [] | |
| factor_min = 1 - error_fraction | |
| factor_max = 1 + error_fraction | |
| for _ in range(parts - 1): | |
| random_factor = random.uniform(float(factor_min), float(factor_max)) | |
| factor = Decimal(str(random_factor)) | |
| part = base_part * factor | |
| parts_list.append(part) | |
| last_part = total_amount - sum(parts_list) | |
| parts_list.append(last_part) | |
| return parts_list | |
| total = 120_919 | |
| parts = split_amount_with_error(total) | |
| print("Money Parts:") | |
| for i, p in enumerate(parts, 1): | |
| print(f"Part {i}: {p:.10f}") | |
| print(f"\nSum of parts: {sum(parts):.10f}") | |
| print(f"Original amount: {Decimal(str(total)):.10f}") | |
| print(f"Difference: {abs(sum(parts) - Decimal(str(total))):.10f}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment