[Tutor] help with program

Alan Gauld alan.gauld at yahoo.co.uk
Mon Nov 7 06:52:06 EST 2022


On 07/11/2022 01:36, Enid Villalobos wrote:

> my program works and runs as it should but they want me to define the
> reverseArray function

I assume you mean they want you to design and write a
function called reverseArray()?

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

You need to define a function to replace the call to reverse() above.

Do you know how to define a function? Can you write a function
that simply prints its input list?

If so then start with that and modify it to print each
item in the list individually.

Then modify that so it prints the items in reverse order.

Then modify it so that instead of printing it puts the items
into a new list

Finally, remove all print statements and return the new list.

Rewrite your original program to use your new function.

If you are stuck with any of that tell us about it, including
any code that you have tried.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos





More information about the Tutor mailing list