Izzywizzard

Untitled

Oct 1st, 2021 (edited)
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. import random
  2.  
  3. nodes = ["a", "b", "c", "d"]
  4. distances = [["ab", 20],["ac", 42],["ad", 35],["bc", 30],["bd", 34],["cd", 12]]
  5. routes = ["a", "b", "c", "d", "a"]
  6. i = 0
  7. distance = 0
  8.  
  9.  
  10. def generateRoute:
  11.     j = 0
  12.     usednumbers = []
  13.     for node in nodes:
  14.        
  15.        
  16.  
  17.  
  18. for route in routes:
  19.     start = route
  20.     try:
  21.         end = routes [i + 1]
  22.     except:
  23.         ("nah mate")
  24.  
  25.    
  26.     if i < (len(routes) - 1):
  27.         for journey in distances:
  28.             if journey[0].__contains__(start) and journey[0].__contains__(end):
  29.                 print (f"distance of journey {start} {end} = {journey[1]}")
  30.                 distance = distance + journey[1]
  31.         i = i+1
  32.  
  33. print (f"total distance of route is {distance}")
  34.  
Add Comment
Please, Sign In to add comment