pythonbeginner10 minutes
Create a Function to Calculate the Square of a Number
Write a Python function that takes a single number as input and returns its square. This is a fundamental exercise to practice defining functions and using arithmetic operators.
Challenge prompt
Build a function named square_number that accepts one parameter (a number) and returns the square of that number. For example, if the input is 4, the function should return 16.
Guidance
- • Define a function using the def keyword.
- • Use the parameter inside the function to perform multiplication.
- • Return the result using the return statement.
Hints
- • Remember that squaring a number means multiplying it by itself.
- • If your function parameter is n, then the square is n * n.
Starter code
def square_number(n):
# Your code hereExpected output
square_number(5) should return 25 square_number(10) should return 100
Core concepts
functionsarithmetic operatorsreturn statement
Challenge a Friend
Send this duel to someone else and see if they can solve it.