def dostuff(self):
whatever you need the code to do
doagain = input('Want to do this again? y/n ')
while doagain != 'n':
whatever you need the code to do
doagain = input('Want to do this again? y/n ')
class thingamajig():
def __init__(self):
pass
def dostuff(self):
number = random.randint(0, 3)
if number == 3:
self.dostuff()
thing = thingamajig()
thing.dostuff()
class thingamajig():
def __init__(self):
pass
def dostuff(self):
doagain = input('Want to do this again? y/n ')
if doagain == 'y':
self.dostuff()
thing = thingamajig()
thing.dostuff()
在dostuff中创建while循环,例如:
注意,必须使用C++中的D/while循环来解决必须重新编码代码的问题,但对于Python
则如此。这就是你如何做到的:
这个类只知道它的参数和它自己的变量。Self是一个会说“this class”的关键字
那么:
相关问题 更多 >
编程相关推荐