Python Game:Rolling the dice

Configurare noua (How To)

Situatie

This is a classic “roll the dice” program.

Solutie

Pasi de urmat

We will be using the random module for this, since we want to randomize the numbers we get from the dice. We set two variables (min and max) , lowest and highest number of the dice.

We then use a while loop, so that the user can roll the dice again. The roll_again can be set to any value, but here it’s set to “yes” or “y”, but you can also add other variations to it.

import random
min = 1
max = 6

roll_again = "yes"

while roll_again == "yes" or roll_again == "y":
    print "Rolling the dices..."
    print "The values are...."
    print random.randint(min, max)
    print random.randint(min, max)

    roll_again = raw_input("Roll the dices again?")

Tip solutie

Permanent

Voteaza

(1 din 7 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?