Storing data in a dictionary
The surface you see below is called circular paraboloid:
It can be described by the following equation: $$ \frac{x^2}{a^2} + \frac{y^2}{a^2} = z $$ Let's set the coefficient \(a\) to 1. Therefore, the radius at each cut will be equal to \(\sqrt{z}\).
Your task is to create a dictionary that stores the mapping from the pair of coordinates \((x, y)\) to the \(z\) coordinate (the lists storing considered ranges for \(x\) and \(y\) are given: range_x
and range_y
, respectively).
This exercise is part of the course
Practicing Coding Interview Questions in Python
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
circ_parab = dict()
for x in range_x:
for y in range_y:
# Calculate the value for z
z = ____
# Create a new key for the dictionary
key = ____
# Create a new key-value pair
circ_parab[____] = ____