Displaying certain values in Python

2

I need help with the following:

  • I have a variable that generates random integers from (0 to 400).
  • In a certain number of executions, I want the value (s) and position (s) of the lower value (s) to be 100.
  • I have a code (see below) that I am working on, but it is not acting properly.

Where am I going wrong?

My code

from random import randint

aleatorio = randint(0,400)
maximo = 100
for i in range(1,maximo + 1):
    if aleatorio < 100:
        print (aleatorio[i])
    
asked by anonymous 26.02.2017 / 18:41

1 answer

3

The best way is to use a dictionary, where each key can be the position of the corresponding value less than 100:

from random import randint

pos = {}
for idx, val in enumerate(range(400)):
    rand_num = randint(0, 400)
    if rand_num < 100:
        pos[idx] = rand_num

DEMONSTRATION

    
26.02.2017 / 18:53