fbpx

Replacing Default Parameters in Python

Is ask_ok(‘Howdy?’, 5) a valid function call?   def ask_ok(prompt, retries=4, reminder='Repeat!'): while True: ok = input(prompt) if ok in ('y', 'ye', 'yes'): return True if ok in ('n', 'no', 'nop', 'nope'): return False retries = retries – 1 if retries < 0: raise ValueError('invalid user response') print(reminder)   This puzzle introduces the concept of …

Replacing Default Parameters in Python Read More »