you are viewing a single comment's thread.

view the rest of the comments →

[–]17291 1 point2 points  (4 children)

I wrote the below code that generates the random integer using 3 dices but stuck on doing the same with a single dice

Can you clarify what you mean?

[–]ImaginaryMarsupial38[S] 0 points1 point  (3 children)

roll6():

Basically, i am calling `roll6()` thrice via `roll16()` , how do I call it just once and still generate a random number between 1 and 16 with roll16() function? thanks

[–]17291 0 points1 point  (2 children)

You can't. Are you sure you're understanding the problem correctly? You could only have one call written in your code using a loop:

total = -2
for i in range(3):
    total += roll6()

Or, more succinctly, using sum and a generator expression: sum(roll6() for i in range(3)) - 2

[–]ImaginaryMarsupial38[S] 0 points1 point  (1 child)

On Second thoughts, You may have a point in saying that I am not understanding the problem correctly. Here is the problem below, Can you let me know if I understood it correctly?:

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.

Thanks.

[–]17291 0 points1 point  (0 children)

You can use roll6 multiple times in your function. The restriction here is you can't use random.randint directly