Python Foundations - Assessments

20 / 54

Types of Functions

Functions, like the one you defined in the last exercise perform an action but don't return a value. They are called void functions. You almost always want to do something with the result. For example, you might assign it to a variable or use it as part of an expression:

def void_function(number):
    num = number
    print(num)

Void functions might display something on the screen or have some other effect, but they don't have a return value. If you try to assign the result to a variable, you get a special value called None.

The value None is not the same as the string "None". It is a special value that has its own type:

print(type(None))

It returns <class 'NoneType'>

Some of the functions, such as the math functions, return certain results.

def multiply(a, b):
    multiplication = a * b
    return multiplication

multiplication_numbers = multiply(1,2)

This function when called returns the result of the multiplication of numbers a and b, i.e 2 and stores it in the variable multiplication_numbers.

INSTRUCTIONS
  • Define a function with name new_function that takes an argument num and returns its multiplication with π.
  • Define a void function with the name void_function which takes two arguments num1 and num2 which makes the call to new_function with an argument as num1 raised to the power of num2.
  • Within the void_function print the value returned by the call.
  • In a new cell, call void_function with arguments as 4.6 and 7.3.


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

Loading comments...