Countries distributed with random.choice() - more comprehensible code style

This commit is contained in:
Jakob Rosenberger 2022-07-26 16:57:33 +02:00
parent 8e2d6b008a
commit 43053d7e32
1 changed files with 8 additions and 12 deletions

20
main.py
View File

@ -177,7 +177,13 @@ if __name__ == '__main__':
print(gebDict)
print(gestDict)
print(bevAnzahl)
print(random.random())
bdls = []
weights = []
for key in bevDict.keys():
bdls.append(str(key))
weights.append(int(bevDict[key]) * Populationsfaktor / int(bevAnzahl))
for i in range(int(bevAnzahl)):
gender = 1
@ -185,20 +191,10 @@ if __name__ == '__main__':
gender = 0
age = random.randint(0, 101)
bdl = ""
randBdl = random.random()
BdlCount = 0
for key in bevDict.keys():
BdlCount += int(bevDict[key])
checkWlsk = (BdlCount*Populationsfaktor)/int(bevAnzahl)
if(randBdl < checkWlsk):
bdl = str(key)
break
bdl = random.choices(bdls, weights)[0]
Population.append(Mensch(age, gender, bdl))
Simulation = Simulation(Population)
Simulation.simulate()
# See PyCharm help at https://www.jetbrains.com/help/pycharm/