Flash Sale: Flat 70% + Addl. 25% Off on all Courses | Use Coupon DS25 in Checkout | Offer Expires In

  Enroll Now

Parameters and Arguments

Some of the built-in functions we have seen require arguments. For example,

  • When you call math.cos you pass a number as an argument.
  • math.pow takes two arguments, the base and the exponent to calculate the exponential of some number.

Inside the function, the arguments are assigned to variables called parameters. Here is an example of a user-defined function that takes an argument:

def print_name(value):
    x = value
    print(value)

This function assigns the argument to a parameter named value. When the function is called, it assigns the value to x and then prints the value of the parameter (whatever it is).

The same rules of composition that apply to built-in functions also apply to user-defined functions, so we can use any kind of expression as an argument for print_name:

print_name(str(math.cos(0)))

It prints 1.0

The argument is evaluated before the function is called, so in the above example, str(math.cos(0)) is evaluated only once.

INSTRUCTIONS
  • Write a function with name my_function which takes one argument with name number. Then, inside the function, write these statements,

    1 - Store the number in a variable xyz
    2 - Convert it into str and store it in xyz_str
    3 - Concatenate cloudxlab to xyz_str
    4 - print xyz_str

  • Test your function by passing an argument 10. It should print 10cloudxlab.


No hints are availble for this assesment

Answer is not availble for this assesment


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...