class should support the following operations.
Description | Method |
---|---|
Create an NSet. Let N = 1, if N is not provided to the constructor. | NSet(N) |
Add a value to the NSet | add(value) |
Remove one occurrence of a given value from the NSet | remove(value) |
How many occurrences of a value are in the NSet? | count(value) |
Does the NSet contain a given value? | contains(value) |
How many values are in the NSet? | total() |
How many different values are in the NSet? | countUnique() |
Return a string representation of the NSet | __str()__ |
Set the value of N | setN() |
x = NSet(3)
for i in range(3):
x.add("X")
print(1, x)
x.add("X")
print(2, x)
x.add("y")
print(3, x)
x.remove('X')
print(4, x)
print("5 Count of y:", x.count('y'))
print("6 Contains z:", x.contains('z'))
x.add('a')
x.add('a')
x.add('a')
print(7, x)
print("8 Total Count:", x.total())
print("9 Total Unique:", x.countUnique())
x.setN(1)
print(10, x)
Expected Output
1 ['X', 'X', 'X']
2 ['X', 'X', 'X']
3 ['X', 'X', 'X', 'y']
4 ['X', 'X', 'y']
5 Count of y: 1
6 Contains z: False
7 ['X', 'X', 'y', 'a', 'a', 'a']
8 Total Count: 6
9 Total Unique: 3
10 ['X', 'y', 'a']
guideOfSAT asked a year ago
Reading books is a great way to learn. Here are some of the books we recommend.
Here is the answer:
davidmacago answered a year ago