python3 练习题100例 (十四)

贴吧上见到的题


python3 练习题100例 (十四)_第1张图片


#!/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)

 

你可能感兴趣的:(python3)