Python 石头 剪刀 布

di = {1: '石头', 2: '剪刀', 3: '布'}
def win(x, y):
	if len({x[0], y[0]}) == 1:
		print('平局.')
	else:
		if {x[0], y[0]} == {1,3}:
			w = sorted([x, y])[1]
			l = sorted([x, y])[0]
		else:
			w = sorted([x, y])[0]
			l = sorted([x, y])[1]
		print('%s 的 %s 赢了 %s 的 %s!' % (w[1], di[w[0]], l[1], di[l[0]]))

w = win((2, '李四'),(1, '张三'))
张三 的 石头 赢了 李四 的 剪刀!

  

posted @ 2018-03-28 10:05  edwardgui  阅读(194)  评论(0编辑  收藏  举报