Created
March 16, 2020 14:26
-
-
Save jshmlr/334ff5fa81c83d61929f5121b3110c98 to your computer and use it in GitHub Desktop.
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
#!/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 |
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
#!/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