Python3 Exercises 100 Questions--022

Source: Internet
Author: User

For a relaxing weekend, do some more questions.

Original title Link: http://www.runoob.com/python/python-exercise-example22.html

title: Two table tennis team to play, each out three people. Team A for A,b,c three, team B for X, Y, z three people. Have drawn lots to determine the contest list. Someone asked the team for a list of matches. A says he does not compare with X, C says he does not compare with x,z, please compile the procedure to find out the list of the three teams.

Analysis: This question can refer to exercise 001, can be converted into a sorting problem.

As long as solving the correspondence between A,b,c and X, Y and Z, the problem can be considered as ABC's order of XYZ. You can use the permutations function.

My Code:

defFun (): forIinchPermutations (['x','y','Z'],3): #枚举出所有xyz的排序if(i[0]!='x'  andi[2]!='x'  andi[2]!='Z'): #卡xyz顺序的条件Print("a:%s,b:%s,c:%s"% (I[0],i[1],i[2]))

Thinking:

The key is to think of the correspondence in order, so there is a preliminary idea--using loops, and only considering the order of XYZ.

Python3 Exercises 100 Questions--022

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.