# [Tutor] help with program

ThreeBlindQuarks threesomequarks at proton.me
Mon Nov 7 11:22:57 EST 2022

```
Alan provided a fairly detailed step by step suggestion which answers one of many possible questions if done carefully. It has lots of extra and later retracted steps meant to teach and assumes you are a beginner.

I go a bit further back and ask that you make sure you understand what the question is perhaps by looking at the original assignment description that you paraphrased or asking the teacher or looking at what else was taught recently or is in the textbook.

It does sound like Alan's guess is what is wanted and the goal is to take any thing you call an array and reverse it. But it is not that simple. Your example uses the built-in python data structure we normally call a "list" as in [9,8,7,6,5] but there are other python data structures that also have a concept of being reversible.

So some of these data structures may be objects with a built-in reverse functionality and some may change the order internally so the data structure is changed and some may return a copy in the new order. Generally calling a function to get the reverse might be expected to not change the argument supplied but return a new one.

There are oodles of ways to play with a list and Alan is not specifying any one way, albeit his sequence of steps suggests some ways more than others such as when he suggests you print one at a time.

The choice of how to do it depends on what has been taught in your class. Do you already know how to determine how many items are in your list/array? Do you know how to do loops? Do you know how to create slices including a way to specify starting at the end and going back by ones?

And is your function required to work only on one kind of data structure? What if the object is a numpy array or sequence or some kind of matrix or dataframe? My guess is it needs to only work for one scenario and return an object of the same kind. But you need to know.

And consider edge cases. What should your reverser return if it gets an empty list/array? What if it gets a single thing not in a list? What should it do if given an argument that it cannot handle or something weird like a generator of all primes.

Chances are you are not being asked to handle complex cases. Chances are you are not being asked to write a member function meant to be placed in objects of type "array" that provide the functionality as in your early attempt. My point is that your description is not detailed enough to allow us to be sure of what the required result should be. Alan provided a reasonable guess that if you fill it in properly will get you a result you can test. But if the request is a bit different, make sure you understand it rather that suggest his method is wrong.

As to specifics, your example is a bit disconcerting on these lines:

original_array = [9, 8, 7, 6, 5]
print("original contents of array:",original_array)
original_array.reverse() #reversing using reverse()

print("Reversed contents of array:",original_array)

The above looks like it reverses the array INTERNALLY. It changes it permanently as you seem to print the original before and after.

I suspect your assignment is to have a line like:

print("Reversed contents of array:", reverseArray(original_array))

Meaning take the original array and LEAVE IT ALONE but ask a function to take it and calculate a new array with the items reversed and return that.

Just make sure you understand the question and then finding a solution can be done.

Sent with Proton Mail secure email.

------- Original Message -------
On Sunday, November 6th, 2022 at 8:36 PM, Enid Villalobos <alex.ochoa0429 at gmail.com> wrote:

> I need to create a reverse program using the reverseArray function
>
> my program works and runs as it should but they want me to define the
> reverseArray function
>
> I am copying my program below
>
> #The original array
> original_array = [9, 8, 7, 6, 5]
> print("original contents of array:",original_array)
> original_array.reverse() #reversing using reverse()
>
> print("Reversed contents of array:",original_array)
>
> when i run this program my output is this:
> original contents of array [9,8,7,6,5]
> reverse contents of array [5,6,7,8,9]
> But they want me to use the array function
>