conv=int, sep=';') elif action == 'w': g.write(safe_open(' Enter file name to write', 'w', 'Could not open this file for writing', default=None), sep=';') elif action == 'q': break elif action == 'rg': g = random_graph( prompt.for_int(' Enter number of nodes in graph', is_legal=predicate.is_non_negative), prompt.for_int_between(' Enter connectivity percentage', 0, 100)) elif action == 'cc': print(connected_components(g)) elif action == 'mst': print(minimum_spanning_tree(g)) elif action == 'sym': make_symmetric(g) else: print(' Unknown command') except AssertionError as report: print(' AssertionError exception caught:', report) except Exception as report: import traceback traceback.print_exc() print('\nFinished testing Graph')
o - pips_on a - all_pips ? - pip_sum = - pips_same _ - __str__ Command""" d = Dice(eval(prompt.for_string('Enter list of max pips', default='[6,6]'))) while True: action = prompt.for_char(command_prompt, legal='rnmsoa?=_.Dq') try: if action == 'r': d.roll() elif action == 'n': print(' Number of dice =',d.number_of_dice()) elif action == 'm': print(' all pip maximums =',d.all_pip_maximums()) elif action == 's': print(' rolls =',d.rolls()) elif action == 'o': i = prompt.for_int_between(' Enter die #', 0, d.number_of_dice()-1) print(' pips on die #',str(i),' =',d.pips_on(i)) elif action == 'a': print(' all pips =',d.all_pips()) elif action == '?': print(' pip sum =',d.pip_sum()) elif action == '=': print(' pips all the same =',d.pips_same()) elif action == '_': print(' str =',str(d)) elif action == '.': exec(prompt.for_string(' Enter command to exec (instance=d)')) elif action == 'D': d.standard_rolls_for_debugging() elif action == 'q': break else: print(' Unknown command') except AssertionError as report: print(' AssertionError exception caught:', report) except Exception as report: import traceback traceback.print_exc() print('\nFinished testing Dice')
= - pips_same _ - __str__ Command""" d = Dice(eval(prompt.for_string('Enter list of max pips', default='[6,6]'))) while True: action = prompt.for_char(command_prompt, legal='rnmsoa?=_.Dq') try: if action == 'r': d.roll() elif action == 'n': print(' Number of dice =', d.number_of_dice()) elif action == 'm': print(' all pip maximums =', d.all_pip_maximums()) elif action == 's': print(' rolls =', d.rolls()) elif action == 'o': i = prompt.for_int_between(' Enter die #', 0, d.number_of_dice() - 1) print(' pips on die #', str(i), ' =', d.pips_on(i)) elif action == 'a': print(' all pips =', d.all_pips()) elif action == '?': print(' pip sum =', d.pip_sum()) elif action == '=': print(' pips all the same =', d.pips_same()) elif action == '_': print(' str =', str(d)) elif action == '.': exec(prompt.for_string(' Enter command to exec (instance=d)')) elif action == 'D': d.standard_rolls_for_debugging() elif action == 'q': break
elif action == '.' : exec(prompt.for_string(' Enter command to exec (instance=g)')) elif action == 'in' : print(' iteration order =',[i for i in g.nodes()]) elif action == 'ie' : print(' iteration order =',[i for i in g.edges()]) elif action == 'iin': n = prompt.for_string(' Enter node to check') print(' iteration order =',[i for i in g.in_nodes(n)]) elif action == 'iie': n = prompt.for_string(' Enter node to check') print(' iteration order =',[i for i in g.in_edges(n)]) elif action == 'ion': n = prompt.for_string(' Enter node to check') print(' iteration order =',[i for i in g.out_nodes(n)]) elif action == 'ioe': n = prompt.for_string(' Enter node to check') print(' iteration order =',[i for i in g.out_edges(n)]) elif action == 'q' : break elif action == 'r' : g.read(safe_open(' Enter file name to read','r','Could not find this file',default=None),conv=int,sep=';') elif action == 'w' : g.write(safe_open(' Enter file name to write','w','Could not open this file for writing',default=None),sep=';') elif action == 'q' : break elif action == 'rg' : g = random_graph(prompt.for_int(' Enter number of nodes in graph',is_legal=predicate.is_non_negative), prompt.for_int_between(' Enter connectivity percentage',0,100)) elif action == 'cc' : print(connected_components(g)) elif action == 'mst' : print(minimum_spanning_tree(g)) elif action == 'sym' : make_symmetric(g) else: print(' Unknown command') except AssertionError as report: print(' AssertionError exception caught:', report) except Exception as report: import traceback traceback.print_exc() print('\nFinished testing Graph')