Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- nodes = ["a", "b", "c", "d"]
- distances = [["ab", 20],["ac", 42],["ad", 35],["bc", 30],["bd", 34],["cd", 12]]
- routes = ["a", "b", "c", "d", "a"]
- i = 0
- distance = 0
- def generateRoute:
- j = 0
- usednumbers = []
- for node in nodes:
- for route in routes:
- start = route
- try:
- end = routes [i + 1]
- except:
- ("nah mate")
- if i < (len(routes) - 1):
- for journey in distances:
- if journey[0].__contains__(start) and journey[0].__contains__(end):
- print (f"distance of journey {start} {end} = {journey[1]}")
- distance = distance + journey[1]
- i = i+1
- print (f"total distance of route is {distance}")
Add Comment
Please, Sign In to add comment