-1

i just make a code that randomly choose a number between 1000 - 9999 for 200 times. now how do i put these number into a specific range like (1000 - 2499) and (2500- 4999) i wanted the output to be like this.

(Example)

1000 - 2499 = 150 number 2500 - 4999 = 50 number 

and how do i know how many of my number is even and divisible by 5?

This is how i generate my number =

import random x = list(range(1000,9999)) x = random.sample(x,200) print (x) 

Any help is much appreciated.

4
  • random.randint(min,max) Commented Jan 21, 2021 at 18:01
  • Does this answer your question? Generate random integers between 0 and 9 Commented Jan 21, 2021 at 18:02
  • i already generated the number. now i need to put those generated number in a specific range. Commented Jan 21, 2021 at 18:17
  • ah now I got it :) Commented Jan 21, 2021 at 18:17

1 Answer 1

1

Maybe this helps you:

import random x = list(range(1000, 9999)) x = random.sample(x, 200) range_low = [num for num in x if num<2500] range_high = [num for num in x if num>=2500] even = [num for num in x if num%2==0] odd = [num for num in x if num%2==1] 
Sign up to request clarification or add additional context in comments.

6 Comments

Hai. I meant after the number is produce by random, Each number will go into an specific range. let say the code randomly produce 10,3,5,1 and 8. These number will go into a range like this ( Even Number : 2 , Odd number : 3) can you help me out?
so you want to count how many odd and even numbers there are?
I see. I edited the answer, now range_low and range_high will contain numbers between 1000-2499 and 2500-9999, respectively, after the random numbers are generated. Lists even and odd contain even and odd (duh!) values of x. If you want to get how many numbers, just do len(even) and len(odd).
You are a legend. Thanks man
@Rusyaidi happy to help, if you're satisfied with the solution please accept & upvote the answer as per Stack Overflow guidelines.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.