Question: edef fix word(action, word): Given an action string which should be one of: -rev', 'mixup', '-noe', '-rand, And a word string. Return the fixed form

 edef fix word(action, word): Given an action string which should be
one of: -rev', 'mixup', '-noe', '-rand", And a word string. Return the

edef fix word(action, word): Given an action string which should be one of: -rev', 'mixup', '-noe', '-rand", And a word string. Return the fixed form of the word with that action applied. Return the empty string if the action string is not recognized. if (action- rev!): return rev(action, word) if (action. ixur.:12: return mixup(action, word) if (action. noe): return noe(action, word) if (action Grand : The -rand Problem Finally it is time to add code to fix_word() to handle the -rand action. When -rand the action passed in to fix word, it means that fix_word() should select one of the actions, -rev -mixup -noe, at random, and apply that action to the passed in word. There are several reasonable ways to do this. The random module has two functions of interest here. random.randrange(n) - returns random int 0..n-1 random.choice(1st) - returns a randomly selected item from Ist >>> random.randrange(5) >>> random.randrange (5) >>> random.randrange (5) >>> random.randrange (5) >>> >>> random.choice(['a', 'b', 'c']) >>> random, choice(['a', 'b', 'c']). >>> random.choice(['a', 'b', 'c']). >>> random.choice(l'a', 'b', 'c'l) You do not need to write Doctests for the -rand case, since testing a random algorithm is difficult (although not impossible). Your existing Doctests should at least ensure that adding the -rand code does not break the previous functionality of the-rev-mixup -noe actions

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!