Question: Python Programming Question / Problem: tasks_tostr(dg, keys) - This function returns a string representation of a digraph represented by a dictionary of tasks (dg) in

Python Programming Question / Problem:

tasks_tostr(dg, keys) - This function returns a string representation of a digraph represented by a dictionary of tasks (dg) in the order defined by the list of keys in that dictionary. Each task will be on a new line within the string, and will be formatted as described for the task_tostr function above. This function does not print out the tasks; it returns a string that can be printed out in another part of the program.

MY CODE: (issue in code)

fs1 = '{0:10} {1:10} {2:^20} {3:10}'def tasks_tostr( dg, keys ):

taskstr = head for key in dg: if key in keys: taskstr += fs1.format(key['tid'], key['dur'], key['preds'], key['ct']) + ' ' return taskstr

TESTING:

fs1 = '{0:10} {1:10} {2:^20} {3:10}'

t1 = {'tid': 'a', 'dur': 10, 'preds': ('b','c'), 'ct': 12} t2 = {'tid': 'b', 'dur': 7, 'preds': (), 'ct': 0} t3 = {'tid': 'c', 'dur': 4, 'preds': ('b',), 'ct': -1}

dg = {t1['tid']: t1, t2['tid']: t2, t3['tid']: t3}}

keys = ['a', 'c']

Expected Output:

"Task name Duration Predecessors Crit. Time

a 10 ('b', 'c') 12

c 4 ('b',) -1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!