Friday, July 26, 2019

Default value for returning a function value

Script

#!/usr/local/bin/python3.5

def get_response(choice='No response, try again!!!')
        if choice is 'y':
                choice="Yes"
        elif choice is 'n':
                choice="No"
        elif choice is 'm':
                choice="May be"
        print(choice)

get_response('y')
get_response('n')
get_response('m')
get_response('k')
get_response('r')
get_response('Y')
get_response('N')
get_response()

Execution

Yes
No
May be
k
r
Y
N
No response, try again!!!




No comments:

Post a Comment