In this python dictionary program, we will create a dictionary in the given form of (n^3).
Steps to solve the program
- Take the value of n and create an empty dictionary.
- User for loop with range function to iterate over the given number.
- Add that number as the key and its cube as its value.
- For calculating the cube use n**3.
- Print the output.
n = 4
D1 = {}
for i in range(1,4+1):
D1.update({i:i**3})
print(D1)
Output :
{1: 1, 2: 8, 3: 27, 4: 64}