Python exercise Questions 4-digit three-digit non-repetition, python exercise questions
I heard that doing exercises is the best way to master a programming language, so I will try to have over 100 questions first.
----------------------------------------------------------------------
[Python exercise 001]There are 1, 2, 3, and 4 numbers. How many three numbers can be composed of different and non-repeated numbers? What is it?
This question is relatively simple. The idea is to first determine the number of digits, then the number of digits and the number of digits. From 1 to 4, the four numbers are all in a loop.
Res = [] for I in range (1, 5): for j in range (1, 5): for k in range (1, 5): res. append (I * 100 + j * 10 + k) print (res)
If you are not sure whether the results are repeated, you can change the last row to print (set (res) and change the res type from list to set ). Because the set does not allow repeated values, the results are not repeated.