Question: This is a solved python class function, and I do not understand whyi increment is used in the generate function and then one is taken

This is a solved python class function, and I do not understand whyi increment is used in the generate function and then one is taken away. Below I have included the equation and bolded the part I find confusing. The purpose of the the program is to take a given number, and increment it by one everytime the user would ask for .generate() , as well as to reset to the original input number upon user request. THANK YOU!

class SerialGenerator:

"""Machine to create unique incrementing serial numbers.

>>> serial = SerialGenerator(start=100)

>>> serial.generate()

100

>>> serial.generate()

101

>>> serial.generate()

102

>>> serial.reset()

>>> serial.generate()

100

"""

def __init__(self, start=0):

self.start = start

self.next = start

def generate(self):

self.next += 1

return self.next - 1

def reset(self):

self.next = self.start

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!