Learn Python: Modules/Modules Python Random


#1

Hi! Does anyone know why we need “for i in range(101)” on the following code?
It works perfectly without it, but on the hint it’s said that should be done like this… Any clue?

Thanks!

Import random below:

import random

Create random_list below:

random_list = [random.randint(1,101) for i in range(101)]

Create randomer_number below:

randomer_number = random.choice(random_list)

Print randomer_number below:

print(randomer_number)

Here’s a link to the exercise:

https://www.codecademy.com/paths/computer-science/tracks/cspath-python-objects/modules/cspath-modules/lessons/modules-python/exercises/modules-python-random


#2

This will cause our program to output 101 random numbers (1…101) in a list.

>>> len(random_list)
101
>>> 

That is a list comprehension that inserts one new random integer for each stride of the range.