How to Figure Out All Digit Combinations in Python


Here this example shows how to accept three characters and print all possible combinations of these characters in Python.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

a = input("Please input three characters separated by SPACE: ")
b = a.split()
for i in range(0, 3):
    for j in range(0, 3):
        for k in range(0, 3):
            if i != j and j != k and k != i:
                print(b[i], b[j], b[k])

Output:

Please input three characters separated by SPACE: 1 a 9
1 a 9
1 9 a
a 1 9
a 9 1
9 1 a
9 a 1
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments