"Python" programming language Introduction Classic 100 cases--22

Source: Internet
Author: User

1 #题目: Two table tennis team to play, each out of 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.


Code:


2 3 ' a '! = ' x ' 4 ' c '! = ' x ' 5 ' c '! = ' Z ' 6 7 if (' x '! = ' A ') and (' x '! = ' C '): 8 print (' x---B ') 9 if ' C '! = ' Z ': print (' Z---A ') one by one (' Y---C ')


Operation Result:


[email protected] code_100]# python code_22.py x---BZ---ay---c[[email protected] code_100]#


Code Explanation:


  #思路: This problem involves too many judgment conditions, this program only wrote if the case of the branch of the code, according to this format can be listed all the judging conditions, the final run results are the same    2    3  ' A '  !=  ' x '                          #题目给出的预判条件   4  ' C '  !=  ' x '   5  ' C '  !=  ' Z '   6   7 if  (' x '  !=  ' a ')  and  (' x '  !=  ' C '):     #根据前两个预判条件 to determine the first set of against list   8      print  (' x --- b ')                   #打印第一组对阵名单   9     if  ' C '  !=   ' Z ':                     #排除第一组对阵名单, according to the third pre-qualification, determine the second set of match list  10          Print (' z --- a ')               #打印第二组对阵名单  11          print (' y --- c ')                #剩余的两人就是第三组对阵名单


This article is from the "Learning Notes" blog, so be sure to keep this source http://netsyscode.blog.51cto.com/6965131/1748286

"Python" programming language Introduction Classic 100 cases--22

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.