Python exercise Questions 4-digit three-digit non-repetition, python exercise questions

Source: Internet
Author: User
Tags repetition

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.