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
- Create an empty dictionary.
- Use for loop with the range function to iterate over numbers from 1-5.
- Add these numbers as keys and their squares as the values.
- Use n**2 to get the square.
- 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}