CBSE Class 12 Computer Science Question 93 of 120

Review of Python Basics — Question 45

Back to all questions
45
Question

Question 40

Write a Python script to print a dictionary where the keys are numbers between 1 and 15 (both included) and the values are square of keys.

Sample Dictionary

{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121, 12: 144, 13: 169, 14: 196, 15: 225}
Solution
result_dict = {}
for num in range(1, 16):
    result_dict[num] = num ** 2
print("Resulting dictionary:", result_dict)
Output
Resulting dictionary: {1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121, 12: 144, 13: 169, 14: 196, 15: 225}
Answer