-
-
Save Denenberg/20f319fa8935f4eded6916800b073530 to your computer and use it in GitHub Desktop.
Here's a simple program that prints the product of the digits of M^N for all M and N in the given range: Here's an updated version of the program that sorts the results in ascending order:
This file contains 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
# Here's a simple program that prints the product | |
# of the digits of M^N for all M and N in the given range: | |
# Here's an updated version of the program | |
# that sorts the results in ascending order: | |
def product_of_digits(n): | |
result = 1 | |
while n > 0: | |
result *= n % 10 | |
n //= 10 | |
return result | |
results = [] | |
for m in range(2, 10): | |
for n in range(2, 10): | |
results.append((m, n, product_of_digits(m**n))) | |
sorted_results = sorted(results, key=lambda x: x[2]) | |
for res in sorted_results: | |
print(res[0], res[1], res[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment