Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions