您的位置:首页 > 编程语言 > Python开发

Python 统计自己微信好友男女数量及比例

2018-04-13 17:13 274 查看
先发代码import itchat
itchat.login()
friends = itchat.get_friends(update=True)[:]
total = len(friends) - 1
man = women = other = 0for friend in friends[0:]:
    sex = friend["Sex"]
    if sex == 1:
        man += 1
    elif sex == 2:
        women += 1
    else:
        other += 1print (total)
print("男性好友:%.2f%%" % (float(man) / total * 100))
print("女性好友: %.2f%%" % (float(women) / total * 100))
print("其他:%.2f%%" % (float(other) / total * 100))

需要首先 pip install itchat登陆 QR CODE后即可统计出结果。

如下:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: