473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

basic question about random array

Hi, I just started learning Python, here is an assignment I wrote.
Expand|Select|Wrap|Line Numbers
  1. numbers = [54, 5, 81, 70, 36, 3, 44, 13, 99, 60, 51, 26, 73, 18, 9, 82, 83, 67, 63, 53, 15, 9, 29, 68, 45, 21, 33, 10, 5, 52, 85, 52, 57, 99, 84, 42, 31, 74, 56, 31, 5, 79, 42, 13, 15, 35, 73, 34, 40, 98, 7, 70, 70, 2, 82, 21, 62, 19, 50, 33, 26, 84, 28, 49, 25, 67, 80, 12, 82, 4, 67, 19, 67, 57, 83, 67, 22, 17, 36, 77, 6, 59, 3, 4, 39, 90, 24, 28, 78, 7, 46, 8, 1, 47, 91, 20, 0, 56, 65, 75]
  2.  
  3. for X in numbers :
  4.     if (X >= 30) and (X < 60):
  5.         text = " age- " + str(X)
  6.         print text
  7.  
I would like to print the values in order from smallest number to largest number. I know it's probably very very basic but I really just could not solve it. Thanks for all your help.
May 9 '12 #1
1 1381
bvdet
2,851 Expert Mod 2GB
List method sort() will sort the list in place.
Expand|Select|Wrap|Line Numbers
  1. >>> numbers = [54, 5, 81, 70, 36, 3, 44, 13, 99, 60, 51, 26, 73, 18, 9, 82, 83, 67, 63, 53, 15, 9, 29, 68, 45, 21, 33, 10, 5, 52, 85, 52, 57, 99, 84, 42, 31, 74, 56, 31, 5, 79, 42, 13, 15, 35, 73, 34, 40, 98, 7, 70, 70, 2, 82, 21, 62, 19, 50, 33, 26, 84, 28, 49, 25, 67, 80, 12, 82, 4, 67, 19, 67, 57, 83, 67, 22, 17, 36, 77, 6, 59, 3, 4, 39, 90, 24, 28, 78, 7, 46, 8, 1, 47, 91, 20, 0, 56, 65, 75]
  2. >>> numbers.sort()
  3. >>> numbers
  4. [0, 1, 2, 3, 3, 4, 4, 5, 5, 5, 6, 7, 7, 8, 9, 9, 10, 12, 13, 13, 15, 15, 17, 18, 19, 19, 20, 21, 21, 22, 24, 25, 26, 26, 28, 28, 29, 31, 31, 33, 33, 34, 35, 36, 36, 39, 40, 42, 42, 44, 45, 46, 47, 49, 50, 51, 52, 52, 53, 54, 56, 56, 57, 57, 59, 60, 62, 63, 65, 67, 67, 67, 67, 67, 68, 70, 70, 70, 73, 73, 74, 75, 77, 78, 79, 80, 81, 82, 82, 82, 83, 83, 84, 84, 85, 90, 91, 98, 99, 99]
  5. >>> 
May 9 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: noone | last post by:
hello all. I am using this code to randomly select one value from an array. srand (); $rec = array("1","2","3","4","5","6"); $rec = $rec; print $rec; problem is, is sometimes it returns...
7
by: Robin Becker | last post by:
We've been queried about the randomness of some filenames we're producing. I worked through and seemed to satisfy myself that random is being initialised from the system time in C time(&now)...
4
by: Chang Byun | last post by:
Hi, folks, I have a question about structure array as a argument. The below short program is that main function call a subroutine which increases real and imaginary part by 1 respectively in...
21
by: Marc Dansereau | last post by:
Hi all I am new to this forum and to the c programming language. If I understand, the random() function in C return numbers that follow a uniform distribution U(0,1). Can somebody know how to...
15
by: mdh | last post by:
Hi Group, Followed the faq to generate random numbers within a given range, so used this: # include <stdlib.h> # define ULIMIT 100 int(........)
23
by: drazet | last post by:
hi,all i have a question about multidimensional array. int w,(*pw); pw=w; is *(pw+1) wrong?why? and *(w+2),pw and *(pw+2) mean?
0
cindy2
by: cindy2 | last post by:
The next code produces a random 9 by 9 array. It produces exactly one "1" in each row and column: So there are never two or more "1" 's in a row or column: Dim j As Integer Dim k As...
47
by: Energizer100 | last post by:
import java.util; public class Compact { public static int randomArray (int n) { int a = new int; for (int i = 0; i < a.length; i++) { a = Math.random();
6
by: new2coding | last post by:
Hi everyone, I am brand new to programming and am trying to pick up c++ on my own, with the help of some books and online tutorials. I am a business major and figured knowing how to make some...
3
by: keegan90 | last post by:
Hi there, first post so hope it goes well :) Im trying to generate statistics on which quote will be displayed each time i refresh the page. I've stored 10 famous quotes in the $famous_quotes...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.