Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is PYTHON!!!! Part B: random Module functions If we ”import random”, some o

ID: 3781234 • Letter: T

Question

This is PYTHON!!!!

Part B: random Module functions

If we ”import random”, some of the useful function are:

General Syntax

Description

Example

random.randrange(start,stop[,step])

Choose a random item from range(start, stop[, step]).

random.randrange(0,110,10)

random.randint(a, b)

Return random integer in [a, b], including both ends

random.randint(a, b)

random.random( )

Return a value in the range [0,1).

random.random( )

Suppose we wanted to randomly roll a 6-sided die to get a value between 1 and 6. How would you use each of the above to generate a die value between 1 and 6?

General Syntax

Description

Example

random.randrange(start,stop[,step])

Choose a random item from range(start, stop[, step]).

random.randrange(0,110,10)

random.randint(a, b)

Return random integer in [a, b], including both ends

random.randint(a, b)

random.random( )

Return a value in the range [0,1).

random.random( )

Explanation / Answer

import random


print random.randrange(1,6,1) #Start from 1 upto 6,increment by 1

print random.randint(1,6)#generate random int from 1 to 6



==================================

akshay@akshay-Inspiron-3537:~/Chegg$ python dice.py
4
3

====================================

random.random( ) generate floating point heance canot be used for die roll

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote