Skip to content

Instantly share code, notes, and snippets.

@huberf
Last active June 30, 2017 19:33
Show Gist options
  • Save huberf/ee855d6320521b202b7d2f73d67ef4e5 to your computer and use it in GitHub Desktop.
Save huberf/ee855d6320521b202b7d2f73d67ef4e5 to your computer and use it in GitHub Desktop.
Python Calculation for Floormate Likelihood
# General likelhod calculation function
def calc(floorSize, classSize):
# Calculate likelihood of person A being on any given floor
chanceOnCertainFloor = floorSize/classSize
# Chance of person B being in any room on any given floor
chanceFloorMate = (classSize/floorSize) / classSize
# Return chance of person A and person B being on the same random floor
return chanceOnCertainFloor * chanceFloorMate
# Function to prettify the results
def toPercentage(number):
return str(number/100) + '%'
# Example calculation for Wallach
if __name__ == '__main__':
# Get the formatted percentage for Wallach
formattedValue = toPercentage(calc(40, 2500))
# Print to user
print(formattedValue, ' likelihood.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment