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