全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 python论坛
1112 1
2017-04-09
悬赏 1 个论坛币 未解决
Write a Python class that extends the Progression class so that each value
in the progression is the absolute value of the difference between the previous two values. You should include a constructor that accepts a pair of
numbers as the first two values, using 2 and 200 as the defaults.
不知道直接贴码会不会变形。附件是progression的源码
class Progression:
    def __init__(self, start = 0):
        self._current = start
    def _advance(self):
        self._current += 1
    def __next__(self):
        if self._current is None:
            raise StopIteration()
        else:
            answer = self._current
            self._advance()
            return answer
    def __iter__(self):
        return self
    def print_progression(self,n):
        print(' '.join(str(next(self))for j in range(n)))

[size=14.6667px]class FibonacciProgression(Progression):
[size=14.6667px]    def __init__(self, first=0,second=1):
[size=14.6667px]        super().__init__(first)
[size=14.6667px]        self._prev = second + first
[size=14.6667px]    def _advance(self):
[size=14.6667px]        self._prev, self._current = (self._current, self._current-self._prev)

[size=14.6667px]




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2017-4-11 13:02:54
自顶..
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群