New course! Every coder should learn Generative AI!
Try a free lesson0
I want to know about this code?can you explain please.this is afunction in python
def ask_ok(prompt, retries=4, reminder='Please try again!'): 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)
1 Answer
+ 7
This code takes input and evaluate whether the user says yes or no. The acceptable values for yes is 'y', 'ye' and 'yes', while acceptable values for no is 'n', 'no', 'nop' and 'nope'. The function by default provides 4 retries. When the retries run out, a ValueError is raised.