Guest User

Untitled

a guest
Nov 18th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. class Router:
  2.  
  3. def __init__(self, name):
  4. self.__name = name
  5. self.__neighbours = []
  6.  
  7.  
  8. def add_neighbour(self, toadd):
  9. self.__neighbours.append(toadd)
  10.  
  11. def print_info(self):
  12. print(self.__name)
  13. print("N:", end = " ")
  14. print(*sorted(self.__neighbours))
  15. print("R:")
  16.  
  17.  
  18. routers = []
  19.  
  20.  
  21. while True:
  22. command = input("> ")
  23. command = command.upper()
  24.  
  25. if command == "P":
  26. toprint = input("Enter router name: ")
  27. if toprint not in routers:
  28. print("Router was not found.")
  29. else:
  30. Router(toprint).print_info()
  31.  
  32.  
  33. elif command == "C":
  34.  
  35. router1 = input("Enter 1st router: ")
  36. router2 = input("Enter 2nd router: ")
  37.  
  38. Router(router1).add_neighbour(router2)
  39. Router(router2).add_neighbour(router1)
  40.  
  41. elif command == "RR":
  42. pass
  43.  
  44. elif command == "NR":
  45.  
  46. newrouter = input("Enter a new name: ")
  47. if newrouter in routers:
  48. print("Name is taken.")
  49. else:
  50. routers.append(newrouter)
Add Comment
Please, Sign In to add comment