Skip to content
← Back to Community
i didn't get this question can you please explain this ques?
Profile icon
shivam14

Create an @authenticated decorator that only allows the function to run is user1 has 'valid' set to True:

user1 = {
'name': 'Sorna',
'valid': True
}

def authenticated(fn):
def wrapper(*args, **kwargs):
if args[0]['valid']:
return fn(*args, **kwargs)
return wrapper

@authenticated
def message_friends(user):
print('message has been sent')

message_friends(user1)

Voters
Profile icon
GoKul4
Profile icon
GaneshRam07
Profile icon
khushbusuryawan
Profile icon
shivam14
Comments
hotnewtop
Profile icon
[deleted]

This page has all the information you need to solve the problem: https://www.programiz.com/python-programming/decorator