Skip to content

Instantly share code, notes, and snippets.

@jaredpalmer
Created November 25, 2017 22:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jaredpalmer/fb297493aa83426492de7b093ac7cdeb to your computer and use it in GitHub Desktop.
Python Classes
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