Simulate Events (Solution)
I’m going to import
random. Then I should write a function. So, I’m going to say
def roll() because I think this is what we said it should be called. Doesn’t really need to take any input, but what it does is it should return a number from
Great. A slightly different way of doing this is you could, instead of importing the whole
random module, we could say
from random import just the
randint function, and then you could cut it out here and just return a call to
randint(). Exactly the same otherwise.
4. Looks like our die is fair. Yippee! Okay. And you practice importing randomness and then also defining function, which are both things that you’re going to need for the upcoming challenge.
Here, you’ve got the solution again, and I’ve also added a little docstring to the function that just describes what this function does.
from random import
randint and then define the
Become a Member to join the conversation.