Skip to content

Instantly share code, notes, and snippets.

@silgon
Created September 15, 2016 12:58
Show Gist options
  • Save silgon/5be78b1ea0b55a20d90d9ec3e7c515e5 to your computer and use it in GitHub Desktop.
Save silgon/5be78b1ea0b55a20d90d9ec3e7c515e5 to your computer and use it in GitHub Desktop.
Stackoverflow question #39349894
import numpy as np # import library for linear algebra and more utilities
from numpy.random import randint # import random int
# initialize random seed
np.random.seed(4)
houses = ["Gryffindor","Slytherin", "Hufflepuff", "Ravenclaw"]
houses_points = []
for _ in houses:
# houses_points.append(randint(0, 100, randint(60,100)))
houses_points.append(randint(0, 50, randint(2,10)))
houses_participations = []
houses_total_points = []
for house_id in xrange(len(houses)):
houses_total_points.append(np.sum(houses_points[house_id]))
houses_participations.append(len(houses_points[house_id]))
total_participations = np.sum(houses_participations)
# proposed model with weighted total participation points
houses_partic_points = []
for house_id in xrange(len(houses)):
tmp = houses_total_points[house_id]*houses_participations[house_id]/total_participations
houses_partic_points.append(tmp)
# House Participation
print "House\t\tPoints per Participant"
for house_id in xrange(len(houses)):
print "{}:\t{}".format(houses[house_id],houses_points[house_id])
print "\nHouse\t\tNumber of Participations per House"
for house_id in xrange(len(houses)):
print "{}:\t{}".format(houses[house_id], houses_participations[house_id])
print "\nHouse\t\tTotal Points"
for house_id in xrange(len(houses)):
print "{}:\t{}".format(houses[house_id], houses_total_points[house_id])
print "\nHouse\t\tPoints weighted by a participation factor"
for house_id in xrange(len(houses)):
print "{}:\t{}".format(houses[house_id], houses_partic_points[house_id])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment