Modules and imports · 12 / 16 Exercise Medium

Reusable functions

Objective

Create a Python program organized as a reusable module: the functions are defined at the top and the main program only runs when the file is launched directly.

Instructions

  • Define the function square(n), which returns n squared.
  • Define the function is_even(n), which returns True if n is even.
  • Define the function main(), which reads an integer and shows Square: S and Even: E (True or False), each on one line.
  • At the end of the file call main() inside if __name__ == "__main__":.
Input
4
Output
Square: 16
Even: True

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise