Write a program that rolls a dice until the user chooses to exit the program.
Use random module to generate random numbers.
import random
answer = "y"
while answer.lower() == "y":
print("Rolling the dices...")
print(f"\nDie 1 is: {random.randint(1, 6)}")
print(f"Die 2 is: {random.randint(1, 6)}")
answer = input("Roll the dices again?y/n: ")
Output:
Rolling the dices...
Die 1 is: 3
Die 2 is: 1
Roll the dices again?y/n: y
Rolling the dices...
Die 1 is: 2
Die 2 is: 4
Roll the dices again?y/n: y
Rolling the dices...
Die 1 is: 5
Die 2 is: 5
Roll the dices again?y/n: y
Rolling the dices...
Die 1 is: 1
Die 2 is: 5
Roll the dices again?y/n: y
Rolling the dices...
Die 1 is: 2
Die 2 is: 5
Roll the dices again?y/n: y
Rolling the dices...
Die 1 is: 5
Die 2 is: 6
Roll the dices again?y/n: y
Rolling the dices...
Die 1 is: 1
Die 2 is: 3
Roll the dices again?y/n: y
Rolling the dices...
Die 1 is: 4
Die 2 is: 1
Roll the dices again?y/n: y
Rolling the dices...
Die 1 is: 1
Die 2 is: 3
Roll the dices again?y/n: y
Rolling the dices...
Die 1 is: 4
Die 2 is: 6
Roll the dices again?y/n: y
Rolling the dices...
Die 1 is: 5
Die 2 is: 2
Roll the dices again?y/n: y
Rolling the dices...
Die 1 is: 4
Die 2 is: 5
Roll the dices again?y/n: y
Rolling the dices...
Die 1 is: 6
Die 2 is: 5
Roll the dices again?y/n: y
Rolling the dices...
Die 1 is: 1
Die 2 is: 2
Roll the dices again?y/n: y
Rolling the dices...
Die 1 is: 4
Die 2 is: 6
Roll the dices again?y/n: y
Rolling the dices...
Die 1 is: 3
Die 2 is: 6
Roll the dices again?y/n: y
Rolling the dices...
Die 1 is: 6
Die 2 is: 1
Roll the dices again?y/n: y
Rolling the dices...
Die 1 is: 6
Die 2 is: 3
Roll the dices again?y/n: y
Rolling the dices...
Die 1 is: 2
Die 2 is: 2
Roll the dices again?y/n: y
Rolling the dices...
Die 1 is: 5
Die 2 is: 2
Roll the dices again?y/n: n
Comments
Leave a comment