Program to create and print a list where the values are squares of numbers

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
  1. Create a function square.
  2. Use the def keyword to define the function.
  3. Use a for loop with the range function to iterate over numbers from 1-10.
  4. After each iteration print the square of the number.
  5. To get the square of the number use** “(ex.-2**2).
  6. Print the number and its square.
  7. 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

find the even numbers from a given list.

execute a string containing Python code.

Leave a Comment