I want to know about this code?can you explain please.this is afunction in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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)

22nd Feb 2020, 12:55 AM
Prabhjot Singh
Prabhjot Singh - avatar
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.
22nd Feb 2020, 1:19 AM
Hatsy Rei
Hatsy Rei - avatar