Creating the header of function


#1

https://www.codecademy.com/courses/learn-python/lessons/functions/exercises/what-good-are-functions?action=resume_content_item

Hi, I’m trying to understand the different elements of the header of a function. Can you please help me identify the def keyword, name of function, and parameters of function based on the exercise above? Does the parameter include the arithmetic equation set by the variable called bill?

Also, can you also identify which part belongs to the body of the function? Is it everything below the optional comments considered the body of the function? (I’m unsure which is the body vs which is the parameters of a function). Thanks.


#2

def is the keyword
tax is the function name
bill is the parameter

This is the code:

def tax(bill):

this is the general syntax:

keyword function_name(parameter):

i don’t see any arithmetic equation def tax(bill) line

this is the function body:

  """Adds 8% tax to a restaurant bill."""
  bill *= 1.08
  print "With tax: %f" % bill
  return bill

which we can recognize by the indent. In many languages, curly brackets are used:

def tax(bill){
  """Adds 8% tax to a restaurant bill."""
  bill *= 1.08
  print "With tax: %f" % bill
  return bill
}

which might make it a bit more clear what the function body is (everything between { and }

but in python, we have to use indent. we can’t use {}


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.