Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iHerzeleid

macrumors 6502a
Original poster
May 5, 2007
555
0
im a newb at this and just got into it

how can i solve this

Write a program that asks the user to enter a list, and which then outputs
the reverse of the list. Here is an example:

Please enter a list: [1,6,11]

The reverse of [1, 6, 11] is [11, 6, 1]


any idea. and im not supposed to be using the reverse command
 
First, this sounds like a homework assignment. If it is that's fine, but make sure to state that in your message. We don't like doing people's homework for them, but its fine to give you hints and lead you in the right direction.

Is this going to be a Python program run from a command line, or is it being developed in a web page? In the example you gave, do the square brackets ([, ]) need to be there? Also what parts of the program do you really need help on; asking for user input, reading the input in, the logic of reversing the numbers, etc.?
 
Well this is what I'd do (may not be the best idea):

[1] Make a collection which contains the items of the list
[2] Create a new list.
[3] Loop through the collection created in step 1 backwards.
[4] On each iteration add the item to the end of the list created in step 2.
[5] Spit out the result.
 
Just create a loop that decrements the index and prints the list rather than incrementing the index and printing.

In other words:
Since a list can have n elements in the list and is zero-based indexed (starts at zero) start at n -1 (since it's zero-based index) and count down to zero, printing as you go along.
 
Here's a hint:

This is two lines in python.

For the second line, consult the python documentation on list types. Section 3.1.4
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.