Modules Python Namespaces:

Hello, guys!

The exercise says:

  1. Create a variable numbers_b and set it equal to a random sample of twelve numbers within range(1000).

The way I solved this is by generating a list that would contain these numbers and my solution was accepted.

Afterward, I double-checked with another solution provided by the system that also generated a list. My question is: Does random.sample() always generates a sequence that is a list? Or is, in this case, this sequence a list?

Thank you!

You can get the type of value with: type(value), you can also read the documentation for random.sample

Some other things:
Your range is off by one, 1000 is not in range(1000) but it is in yours.
random.sample will not choose the same value twice, so it is not doing the same thing
You’re generating many plots, are you sure that should be in a loop?
Usually if you want to do something 12 times you’d iterate through range(12), that saves you the trouble of keeping count with a variable and reduces the risk of making an off-by-1 mistake

My solution

1 Like