Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write an implementation that satisfies the doc - string in the line which says TODO your implementation here using ONLY Pycharm, please. Then, test the
Write an implementation that satisfies the docstring in the line which says "TODO your implementation here" using ONLY Pycharm, please.
Then, test the function using the lines of code which starts from right below "TODO your implementation here"
Thank you.
class Registryobject:
def initself size, value:
Purpose:
Initialize a registry of a give size filled with the
given value
Preconditions:
size: number of elements in the registry
value: the default initial value for all elements
self.reg value for i in rangesize
def setself i:
Purpose:
Set the registry element at i to True
Preconditions:
i: an index, in the correct range for reg
Postconditions:
the registry value at i is set to True
Return:
none
self.regi True
def resetself i:
Purpose:
Set the registry element at i to False
Preconditions:
i: an index, in the correct range for reg
Postconditions:
the registry value at i is set to False
Return:
none
self.regi False
def isregisteredself i:
Purpose:
Returns the value stored at registry element i
Preconditions:
i: an index, in the correct range for reg
Postconditions:
none
Return:
the value stored at element i
return self.regi
def showself:
Purpose:
Shows the current Registry values
Preconditions:
none
Postconditions:
none
Returns:
none
printselfreg
def extendself size, value:
Purpose:
Extend the registry. This grows the registry to the given size.
The value given will be the new default value for the extended registers.
Preconditions:
size: number of elements in the registry
value: the default initial value for all elements
Postconditions:
IMPORTANT: The previous entries in the registry retain their values.
The registry is expanded. Entries up to the original size are kept the same.
New entries are set to the value provided in the argument.
Returns:
none
Warnings:
This method asserts that the new size is greater than the original Registry size.
assert size lenselfregError in Registry method extendsize value
"Provided size must be greater than the original Registry size."
# TODO your implementation here
import Registry as R
# You can run this after completing Activity
# This test shows that extendto adds one more register
testextendto RRegistry False
testextendtoextendto True
testextendtoshow
# This test shows that extendby adds six more registers
testextendby RRegistry False
testextendbyextendby True
testextendbyshow
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started