What is the syntax to write a function that returns a value?

#to define function
def <function name>(<parameters, if any>):
     <function code here>
     return <value to be returned>

#to call a function
<function name>(<arguments passed to parameters, if any>)
#example with parameters, return statement
def passOrFail(grade):
     if grade>50:
          return 'Student passed'
     else:
          return 'Student failed'
print(passOrFail(100))

#output
Student passed

 

Advertisements