-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.

Sayandip Dutta
  • 15,602
  • 4
  • 23
  • 52
Rusyaidi
  • 1
  • 1

1 Answers1

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]
PApostol
  • 2,152
  • 2
  • 11
  • 21
  • 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? – Rusyaidi Jan 21 '21 at 18:13
  • so you want to count how many odd and even numbers there are? – seven_seas Jan 21 '21 at 18:19
  • 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)`. – PApostol Jan 21 '21 at 18:19
  • You are a legend. Thanks man – Rusyaidi Jan 21 '21 at 18:28
  • @Rusyaidi happy to help, if you're satisfied with the solution please accept & upvote the answer as per Stack Overflow guidelines. – PApostol Jan 21 '21 at 18:35
  • Done upvote. I don,t know why my question got duplicated and being close. I check the other question and i don't even get a single clue. Thank god you answer quickly. Thanks again – Rusyaidi Jan 21 '21 at 18:40