# 使用itchat获取微信好友的男女比例
import itchat
itchat.auto_login(hotReload=True)
friends = itchat.get_friends(update=True)[0:]
# 初始化 男和女的数量
male = female = other = 0
for i in friends[1:]:
    print(i)
    sex = i["Sex"]
    if sex == 1:
        male += 1
    elif sex == 2:
        female += 1
    else:
        other += 1
total = len(friends[1:])  # 总数
# % .2f 保留几位有效数字
print("男性比率:%.4f %%" % (male / total * 100))
print("女性比率:%.4f %%" % (female / total * 100))
print("其他比率:%.4f %%" % (other / total * 100))
# 练习:打印出自己的好友性别比率

 

相关文章:

  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
  • 2021-10-26
  • 2021-07-22
  • 2021-04-29
  • 2021-11-23
猜你喜欢
  • 2021-07-24
  • 2021-07-28
  • 2021-08-04
  • 2021-07-09
  • 2021-08-31
  • 2021-11-18
相关资源
相似解决方案