In this python function program, we will create and print a list where the values are squares of numbers. To find the square of a number we need to multiply that number by itself.
What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.
Steps to solve the program
- Create a function square.
- Use the def keyword to define the function.
- Use a for loop with the range function to iterate over numbers from 1-10.
- After each iteration print the square of the number.
- To get the square of the number use ” ** “(ex.-2**2).
- Print the number and its square.
- Call the function to get the output.
def square():
for i in range(1,11):
print(i,":",i**2)
square()
Output :
1 : 1
2 : 4
3 : 9
4 : 16
5 : 25
6 : 36
7 : 49
8 : 64
9 : 81
10 : 100
Related Articles
Python function program to execute a string containing Python code.
Python function program to access a function inside a function.
Python function program to find the LCM of two numbers.
Python function program to calculate the sum of numbers from 0 to 10.
Python function program to find the HCF of two numbers.
Python function program to create a function with *args as parameters.