@chepner
我最初是这样做的:
class Cub:
def __init__(self, lenght, width, height):
self.lenght = lenght
self.width = width
self.height = height
def volume(self):
return self.lenght * self.width * self.height
def calclenght(self):
return ((self.lenght * 12))
def main():
cub = Cub(3, 4, 5)
print("Volume = ", cub.volume())
print("Total lenght = ", cub.calclenght())
if __name__=="__main__":
main()
结果是:体积=60,长度=36。这是我必须完成的任务:
创建一个类,该类将用于实例化立方体形状的对象。定义一种用于计算立方体体积的方法和另一种用于计算立方体所有边的总长度的方法
将这些方法放在线程中,首先运行第二个线程方法,然后在成功完成后运行第一个线程方法。在此过程中,必须关闭主线
创建两个对象,在这两个对象上调用每个已创建的方法
使用“打印”命令显示这些方法的结果
老实说,这个任务是一个可怕的线程示例,因为在这里完全没有必要这么做。不管怎样,这都是一种方法
实际上,我不确定任务是想让您直接在对象函数中打印结果,还是作为主程序的一部分打印结果。后者就是我在这里所做的,尽管直接分配给可变对象并不是您真正想要做的(它) 但在这种情况下,这并不重要)。如果这是预期的结果,请改用thread queue,它允许您以安全的方式直接获取线程的返回值
这将输出:
相关问题 更多 >
编程相关推荐