Write a program die_function2.py
that has a die()
function that takes a number n
as a parameter, calculates a random number between 1 and n (inclusive), and prints that number out from within the function.
You'll need to import the random
module, and then calculate a random integer using one of several strategies:
int(random.random() * n) + 1
or
random.randrange(n) + 1
The main()
program should call the die()
function a few times so several different random numbers are displayed.
Sample output:
I have rolled a 6-sided die to get the result 3
I have rolled a 20-sided die to get the result 17
I have rolled a 2-sided die to get the result 1