خرید بک لینک

Vote count: 0

I try to inherit from int and write the increase() function for it.

import math


class Counter(int):

    def increase(self):
        self += 1
        # it should be less then 2**32
        maximum = math.pow(2, 32)
        if self > maximum:
            self -= maximum



counter = Counter(10)
print counter
counter.increase()
print counter
counter.increase()
print counter

ouput:

10
10
10

It doesn't work! Why and how to write the code?

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: شنبه 22 خرداد 1395 ساعت: 20:59

صفحه بندی