Last active
August 4, 2021 16:56
-
-
Save spraveenitpro/aca657a1ad1b4dd541de5ccf9edf0491 to your computer and use it in GitHub Desktop.
Write a program in Python where you generate a random integer from 1 to 16 inclusive where your only random number generator is a six-sided die. Assume a function named roll6 which returns a 1, 2, 3, 4, 5 or 6 and write a function named roll16 which returns an integer between 1 and 16 inclusive.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
# Roll6 function to return random number between 1 and 6 | |
def roll6(): | |
return(random.randint(1,6)) | |
# Roll16 function to call Roll6 function thrice | |
# Our range with 3 dices are 3 - 18, so I am deducting 2 to set the range from 1 to 16 | |
def roll16(): | |
value = (roll6() + roll6() + roll6()) - 2 | |
return value | |
# Print the random value returned by roll16 | |
print(roll16()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment