Kom igångKom igång gratis

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

Den här övningen är en del av kursen

Practicing Coding Interview Questions in Python

Visa kurs

Interaktiv övning med praktiskt arbete

Testa den här övningen genom att slutföra den här exempelkoden.

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[____] = ____
Redigera och kör kod