本帖最后由 776667 于 2018-6-28 17:04 编辑  
- from random import randint
 
  
- def fun169(x):
 
 -     list_dice_all = []
 
 -     for i in range(x):
 
 -         dice = [randint(1,6) for i in range(3)]
 
 -         list_dice_all.append(tuple(dice))        
 
 -     list_dice_three = sorted([i for i in list_dice_all if len(set(i)) == 1])[::-1]    
 
 -     list_dice_two = [i for i in list_dice_all if len(set(i)) == 2]   
 
 -     list_dice_nope = [i for i in list_dice_all if len(set(i)) == 3]
 
 -     list_dice_nope.sort(key=lambda x:sum(x),reverse=True)
 
 -     list_dice_two_sorted = []
 
 -     for i in range(1,7)[::-1]:
 
 -         for j in range(1,7)[::-1]:
 
 -             for n in list_dice_two:
 
 -                 if n.count(i) == 2 and n.count(j) == 1:
 
 -                     list_dice_two_sorted.append(n)
 
 -     return list_dice_three + list_dice_two_sorted + list_dice_nope
 
  
- if __name__ == '__main__':
 
 -     x = input('请输入掷骰次数:')
 
 -     print(fun169(int(x)))
 
  复制代码- 请输入掷骰次数:30
 
 - [(5, 5, 5), (6, 6, 4), (2, 6, 6), (6, 1, 6), (5, 5, 3), (5, 5, 2), (4, 4, 3), (3, 3, 6), (3, 3, 4), (1, 1, 3), (3, 6, 4), (6, 4, 3), (6, 4, 2), (6, 1, 5), (3, 5, 4), (4, 5, 3), (2, 4, 6), (2, 3, 6), (6, 2, 3), (1, 6, 4), (6, 2, 3), (6, 3, 2), (1, 6, 3), (6, 1, 3), (2, 5, 3), (4, 3, 2), (4, 2, 3), (1, 4, 3), (1, 4, 2), (1, 2, 4)]
 
 - >>> 
 
  复制代码 |