Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Router:
- def __init__(self, name):
- self.__name = name
- self.__neighbours = []
- def add_neighbour(self, toadd):
- self.__neighbours.append(toadd)
- def print_info(self):
- print(self.__name)
- print("N:", end = " ")
- print(*sorted(self.__neighbours))
- print("R:")
- routers = []
- while True:
- command = input("> ")
- command = command.upper()
- if command == "P":
- toprint = input("Enter router name: ")
- if toprint not in routers:
- print("Router was not found.")
- else:
- Router(toprint).print_info()
- elif command == "C":
- router1 = input("Enter 1st router: ")
- router2 = input("Enter 2nd router: ")
- Router(router1).add_neighbour(router2)
- Router(router2).add_neighbour(router1)
- elif command == "RR":
- pass
- elif command == "NR":
- newrouter = input("Enter a new name: ")
- if newrouter in routers:
- print("Name is taken.")
- else:
- routers.append(newrouter)
Add Comment
Please, Sign In to add comment