I&C SCI 32 Lecture Notes - Lecture 8: Init

16 views1 pages

Document Summary

# this module defines a class called counter, which is a kind of object. # called a counter, whose goal is to count how many times its count # its count and returns it, so each time you call count, you"ll receive. # a value one greater than the value you received the previous time. # is also possible to reset the counter and to peek at its count (i. e. , # counter objects have one private attribute, _count, which specifies. # how many times its count() method has been called. # if you run this module in idle, you would be able to do this in the. """initializes a counter with a count of zero""" self. _count = 0 def count(self) -> int: """increments and returns the count""" self. _count += 1 return self. _count def peek(self) -> int: """returns the count without updating it""" return self. _count def reset(self) -> none:

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents