[Tutor] Variable list problem
alan.gauld at yahoo.co.uk
Thu Oct 12 20:16:25 EDT 2017
On 12/10/17 22:29, Le Mar wrote:
> hi i'm wondering if anyone could help me with this exercise:
We can give you tips but we don;t do your homework for you.
> 1. Read an integer number from the console, store the result in a variable n
> 2. Read ‘n’ integers from the console and store them in a list
> 3. Sort the list in reverse order – from highest to lowest
> 4. Loop over the elements in the list and print them each on their own line to the console
Since you give the exact steps needed we have to assume
that there is some part of this that you don't know how
to do. Which step is proving difficult?
1) use the input() function and convert the string to an integer.
2) use a loop (and the same code as in 1) to collect the numbers
in a list
3) lists have methods for sorting and reversing their contents
4) use another loop and the print() function.
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:
More information about the Tutor