对于赋值,我创建了一个类来表示多项式,方法是存储一个带有系数的列表,作为该类的数据成员。你知道吗
尽管我在为它创建最后一个函数时遇到困难"polySequence"
:
A function polySequence which takes a start, end, and step, and returns a generator. The generator will evaluate the polynomial for the value start, then start + end, and so on, up to end and yield these values one at a time. If no step is given, a step of 1 should be used (similar to the range method). As an example, if p represents the polynomial 2x + 1 (coefficient list [1,2]), the code
for val in p.polySequence(0,5):
print(val)
应在单独的行上打印值1、3、5、7和9。你知道吗
下面是我对底部的Polysequence的实现:
看起来您只将第一个参数传递给了polySequence函数。您应该传递所有声明的参数(start、stop和step):
访问polySequence方法的方式不正确。只有静态或类方法被这样调用。您需要实例化该类,然后调用polySequence方法。例如
我还可以看到start变量总是在polySequence方法内部的代码中被覆盖。如果是这样,为什么要在方法中启动参数?你知道吗
相关问题 更多 >
编程相关推荐