0
How can I output the number of connections in this Code?
I have 5 users and I want to output the total connection of each user. Where am I wrong?
2 Respuestas
0
class X():
def __init__(self, size):
self.adj = [ [0] * size for i in range(size)]
self.size = size
def add_friend(self, x, y):
if x > self.size or y > self.size or x < 0 or y < 0:
print("Error")
else:
self.adj[x-1][y-1] = 1
self.adj[y-1][x-1] = 1
def remove_friend(self, x, y):
if x > self.size or y > self.size or x < 0 or y < 0:
print("Error")
else:
self.adj[x-1][y-1] = 1
self.adj[y-1][x-1] = 0
x = X(5)
x.add_friend(1, 3)
x.add_friend(1, 5)
x.add_friend(2, 5)
x.add_friend(2, 4)
x.add_friend(4, 5)
n = int(input())
#your code goes here
total_connections = 0
for i in x.adj:
for j in i:
if j:
total_connections += 1
print(total_connections*5//25)
0
Pls do these changes in your question to make it easier for people to help you:
1. Remove the meaningless tag and include another one with the language name.
2. Include a link to your code in Code Playground - tap "+", then "Code", then your code.
3. Explain what is wrong in the results.
I guess the issue is the print call location, but this is assuming the language is Python. Better not use assumptions in programming...