'How can I make a program that prints Numbers formed by 3 digits or more?

I'm new to programming and I stumbled across an exercise that asked me the following:

Create a program that shows you the numbers formed by 3 digits and prints the biggest as well as the smallest.

Example:

N=472

So the outputs will be:

472, 427,742, 724, 274, 247.
The biggest number is 742 and the smallest is 247.


Solution 1:[1]

Try this for min and max value:

N = 472
sorted_digits = sorted(str(N))
number = "".join(sorted_digits)
print(f"The biggest number is {number[::-1]} and the smallest is {number}.")

EDIT: You can try to use permutations from module itertools for get all numbers:

from itertools import permutations

N = 472
all_permutations = list(map(lambda t: "".join(t), permutations(str(N), len(str(N)))))
print(*all_permutations)

Solution 2:[2]

n=int(input("-Enter Number Of Numbers :"))
x=int(input("-Enter Number :"))
g=x
s=x
for i in range(n-1) :
    x=int(input("-Enter Number :"))
    if x>g :
        g=x
    elif x<s :
        s=x
print("The Greatest Number :",g)
print("The Smaller Number :",s)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2