Q. Write a random number generator that generates random numbers between 1 and 6 (simulates a dice).


Answer :-


import random
min = 1
max = 6
roll_again = "y"
while roll_again == "y" or roll_again == "Y":
    print("Rolling the dice...")
    val = random.randint (min, max)
    print("You get... :", val)
    roll_again = input("Roll the dice again? (y/n)...")


Output :-

Rolling the dice...
You get... : 3
Roll the dice again? (y/n)...y
Rolling the dice...
You get... : 1
Roll the dice again? (y/n)...n

>>>

11 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post