今天逛贴吧,看到有人求助,做了一下。请大家指正!
#!/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = 'Fan Lijun' import random dic = {} fruit = ['香蕉', '草莓', '苹果', '梨子', '西瓜', '芒果', '葡萄'] for i in range(100): f = random.choice(fruit) if f in dic: dic[f] += 1 else: dic[f] = 1 print(dic)
这个简单!