CommencerCommencer gratuitement

Storing data in a dictionary

The surface you see below is called circular paraboloid:

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).

Cet exercice fait partie du cours

Practicing Coding Interview Questions in Python

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de 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[____] = ____
Modifier et exécuter le code