This is a Python Program to accept three distinct digits and print all possible combinations from the digits.
The program takes three distinct numbers and prints all possible combinations from the digits.
1. Take in the first, second and third number and store it in separate variables.
2. Then append all the three numbers to the list.
3. Use three for loops and print the digits in the list if none of their indexes are equal to each other.
Here is the source code of the Python Program to accept three distinct digits and prints all possible combinations from the digits. The program output is also shown below.
a=int(input("Enter first number:")) b=int(input("Enter second number:")) c=int(input("Enter third number:")) d= d.append(a) d.append(b) d.append(c) for i in range(0,3): for j in range(0,3): for k in range(0,3): if(i!=j&j!=k&k!=i): print(d[i],d[j],d[k])
1. User must enter the first, second and third number.
2. All the elements are appending into a list for the ease of comparison.
3. The for loops range from 0-2 which are basically the indexes of the three elements in the list.
4. If none of the indexes are equal to each other, the element associated with the particular element in the list is printed.
Case 1: Enter first number:1 Enter second number:2 Enter third number:3 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1 Case 2: Enter first number:5 Enter second number:7 Enter third number:3 5 7 3 5 3 7 7 5 3 7 3 5 3 5 7 3 7 5
Sanfoundry Global Education & Learning Series – Python Programs.
To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.