The Nile

On the freeform project “The Nile” from “Learn Python 3”, we are asked to unpack the tuple on step 2.
I noticed that the unpacking must be written this way:

from_lat, from_long = from_coords
to_lat, to_long = to_coords

and not this way:

from_coords = from_lat, from_long
to_coords= to_lat, to_long

Can anyone explain why that is?!?

Merci beaucoup!

Consider how the assignment operator works. If we have the following:

a = 1
b = 2

a = b #what happens here?
print(f'a: {a}; b: {b}')


a: 2; b: 2

Assignment when unpacking a tuple happens in the same direction.

The value(s) on the right are assigned to the variable(s) on the left. Nothing really special or unique.

Tuples are immutable and make great persistent read only objects. What’s more, since Python variables can be re-used we can create new tuples from old and assign them back to the same variable.

When unpacking, we need to be informed of what the meaning attached to each value in the tuple actually is. Furthermore, the left-hand side of the assignment must correspond to the number of values in the sequence on the right.

>>> z =  1, 2, 3, 4, 5, 6, 7
>>> a, b, c = z
Traceback (most recent call last):
  File "<pyshell#38>", line 1, in <module>
    a, b, c = z
ValueError: too many values to unpack (expected 3)

In this Project Nile, in Step : 12 how come calculate the driver_time for each driver by multiplying driver.speed by distance . ? shouldn’t it be: distance / driver.speed ?

Relevant Lesson:

It is In the step 12 of the Project Walkthrough video URL:

step 12: time frame 12:45

Thank you very much.

Without seeing the lesson we can’t give an answer, but if what you point out is actually the case, then it is dead wrong. distance over time gives speed; distance over speed gives time. I’m not sure what multiplying distance by speed will give but something unrelated to either in a practical sense.

We need a link to this exercise to suss out anything further. Please post the URL in a reply. Thanks.

Hi,thank you for the quick reply.

please refer the video

Task 12 at 12:45

The video link I could have found on the exercise page. That’s what link I need to further this discourse. Please post the URL in your reply.