Create a dictionary where keys are numbers and values are squares of the keys.

In this python dictionary program, we will create a dictionary where keys are between 1 to 5 and values are squares of the keys.

Steps to solve the program
  1. Create an empty dictionary.
  2. Use for loop with the range function to iterate over numbers from 1-5.
  3. Add these numbers as keys and their squares as the values.
  4. Use n**2 to get the square.
  5. Print the output.
				
					dict1 = {}

for i in range(1,6):
    dict1[i] = i**2
    
print(dict1)
				
			

Output :

				
					{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
				
			

insert a key at the beginning of the dictionary.

find the product of all items in the dictionary.

Leave a Comment