Answer to Question #188156 in Python for Sam

Question #188156

Write a program that rolls a dice until the user chooses to exit the program.

Use random module to generate random numbers.


1
Expert's answer
2021-05-03T07:54:06-0400
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




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS