You are on page 1of 2

# # # # # # #

CS1010S --- Programming Methodology Mission 6 Template Note that written answers are commented out to allow us to run your code easily while grading your problem set.

############### # Pre-defined # ############### def split_string(string, delimiter): return tuple(map(lambda x: x.strip(), string.split(delimiter))) ########## # Task 1 # ########## # (a) def make_bus_stop(bus_stop): return split_string(bus_stop, ",") # Test : vs_stop = make_bus_stop("01012,Victoria St,Hotel Grand Pacific") #print(vs_stop) # (b) (i) def bus_stop_code(bus_stop): return bus_stop[0] # Test : '01012' #print(bus_stop_code(vs_stop)) # (b) (ii) def bus_stop_road(bus_stop): return bus_stop[1] # Test : 'Victoria St' #print(bus_stop_road(vs_stop)) # (b) (iii) def bus_stop_description(bus_stop): return bus_stop[2] # Test : 'Hotel Grand Pacific' #print(bus_stop_description(vs_stop)) # (c) def bus_stop_summary(bus_stop): return bus_stop_code(bus_stop) + ' - ' + bus_stop_road(bus_stop) + ' - ' + b us_stop_description(bus_stop) # Test : '01012 - Victoria St - Hotel Grand Pacific' #print(bus_stop_summary(vs_stop))

########## # Task 2 # ########## def read_bus_stop_data(bus_stop): new = () with open(bus_stop, "r") as file: for line in file: new = new + (make_bus_stop(line),) return new # Test : bus_stops = read_bus_stop_data("bus_stop_code_set.txt") first_stop = bus_stops[0] #print(bus_stop_code(first_stop)) # '01012' #print(bus_stop_road(first_stop)) # 'Victoria St' #print(bus_stop_description(first_stop)) # 'Hotel Grand Pacific' #print(bus_stop_summary(first_stop)) # '01012 - Victoria St - Hotel Grand Pacifi c' ########## # Task 3 # ########## # (a) def lookup_bus_stop_by_code(bus_list, code): for member in bus_list: if code == bus_stop_code(member): return member return 'None'

You might also like