Created
November 25, 2017 22:30
Star
You must be signed in to star a gist
Python Classes
This file contains 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