Created
November 25, 2017 22:30
-
-
Save jaredpalmer/fb297493aa83426492de7b093ac7cdeb to your computer and use it in GitHub Desktop.
Python Classes
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
import math | |
def nCr(num, kVal): | |
"""Returns a nCr combination | |
Args: | |
num (int): The numerator. | |
kVal (str): The size of the set. | |
Returns: | |
float: n Choose r. | |
""" | |
return float(math.factorial(num) / math.factorial(kVal) * math.factorial(num - kVal)) | |
class Game: | |
variable = "blah" | |
def start(self, kVal, num): | |
self.kVal = kVal | |
self.something = num | |
def score(self): | |
"""Print out an instance variable""" | |
print("k: " + str(self.kVal)) | |
def printVariable(self): | |
"""Print out a static class variable""" | |
print(self.variable) | |
thingy = Game() | |
thingy.start(2, 3) | |
thingy.score() | |
thingy.printVariable() | |
other = Game() | |
other.start(10, 3) | |
other.score() | |
other.printVariable() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment