Question: We saw in class that Python offers three seemingly similar, if not entirely interchangeable, data structures: a range, a tuple and a list. All three

We saw in class that Python offers three seemingly similar, if not entirely interchangeable, data structures: a range, a tuple and a list. All three represent a sequence of values, but they offer different (though sometimes overlapping) abilities and are each meant to solve problems of a decidedly different shape. The most important thing to understand when learning the set of tools provided by a programming language is what kinds of problems each of those tools is best used for, so let's consider ranges, tuples, and lists in those terms.
Suppose that you were solving each of the following programming problems.
In a function, users will enter the names of all of the students enrolled in a course, continuing to read them until the user enters an empty one. You'd like to return all of the names from the function.
Given an integer n, generate the first n integers in the Fibonacci sequence. The first integer in the sequence is 0, the second is 1, and each subsequent integer in the sequence is the sum of the two integers that precede it.
Given two Cartesian points in either two-dimensional or three-dimensional space, determine the distance between them. Any two-dimensional point will be treated as though its z-coordinate is 0. What you'll need to decide is how to represent each point.
For each of them, would you use a range, a tuple, or a list? Briefly explain, in a sentence or two, why you made the choice you did. (Note that an answer without any explanation is neither correct nor an honest attempt; the important thing here, as is so often the case in real-world programming, is the "why.")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!