Last active
June 30, 2017 19:33
-
-
Save huberf/ee855d6320521b202b7d2f73d67ef4e5 to your computer and use it in GitHub Desktop.
Python Calculation for Floormate Likelihood
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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