Skip to content

Instantly share code, notes, and snippets.

@mustafa-qamaruddin
Created May 7, 2018 07:49
Show Gist options
  • Save mustafa-qamaruddin/aeaaf7b84756f76605d0f649179df574 to your computer and use it in GitHub Desktop.
Save mustafa-qamaruddin/aeaaf7b84756f76605d0f649179df574 to your computer and use it in GitHub Desktop.
Script to Choose Baby Name
import matplotlib.pyplot as plt
import numpy as np
ls_names = ["Omar", "Zainuddin", "Yahya", "Malek"]
scores = {"Omar": 0, "Zainuddin": 0, "Yahya": 0, "Malek": 0}
for j in range(10):
print("{}/10".format(j), end="\r")
dict_names = {"Omar": 0, "Zainuddin": 0, "Yahya": 0, "Malek": 0}
for i in range(1000):
x = np.random.randint(0, 4)
dict_names[ls_names[x]] += 1
s = [(k, dict_names[k]) for k in sorted(dict_names, key=dict_names.get, reverse=True)]
scores[s[0][0]] += 1
pcts = {}
for k, v in scores.items():
pcts[k] = round(v / 10 * 100, 2)
s = [(k, pcts[k]) for k in sorted(pcts, key=pcts.get, reverse=True)]
print(s)
plt.bar(range(len(pcts)), list(pcts.values()), align='center')
plt.xticks(range(len(pcts)), list(pcts.keys()))
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment