re_loop.py 663 B

123456789101112131415161718192021222324252627
  1. def generate_combinations(n, max_number):
  2. # Initialize the combination
  3. combination = [0] * n
  4. # Generate all combinations
  5. while True:
  6. # Print the current combination
  7. print(combination)
  8. # Increment the combination
  9. i = n - 1
  10. while i >= 0:
  11. if combination[i] < max_number:
  12. combination[i] += 1
  13. break
  14. else:
  15. combination[i] = 0
  16. i -= 1
  17. # If i < 0, we've exhausted all combinations
  18. if i < 0:
  19. break
  20. if __name__ == '__main__':
  21. # Generate all 8-digit combinations
  22. generate_combinations(4, 4)