Skip to content

Instantly share code, notes, and snippets.

@jshmlr
Created March 16, 2020 14:26
Show Gist options
  • Save jshmlr/334ff5fa81c83d61929f5121b3110c98 to your computer and use it in GitHub Desktop.
Save jshmlr/334ff5fa81c83d61929f5121b3110c98 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# create a class
class Pull:
# define the class's attributes
globalCount = 0
globalEpsilon = 0
# create an initializer for the class
def __init__(self, count, epsilon):
self.globalCount = count
self.globalEpsilon = epsilon
# create a function
def pullArm(self, count, epsilon):
self.globalCount += count
return 0
#!/usr/bin/env python
# import the module
import OOPPull
# instantiate the class
instance = OOPPull.Pull(0,0)
print ("globalCount = {}".format(instance.globalCount))
# let's pull the arm
instance.pullArm(1,0)
# now print globalCount again
print ("globalCount = {}".format(instance.globalCount))
# now pass the globalCount as a value
x = instance.globalCount
instance.pullArm(x,0)
# print the result
print ("globalCount = {}".format(instance.globalCount))
# now do it 10 times
i = 0
y = instance.globalCount
for i in range(9):
instance.pullArm(y,0)
# print the result
print ("globalCount = {}".format(instance.globalCount))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment