Question: import random ' ' ' 1 . Initialize two dice with 6 sides each, which can be customized later if desired. 2 . Set the
import random
Initialize two dice with sides each, which can be customized later if desired.
Set the variable active to True to control the main game loop.
Start the main game loop using a while loop with the condition active
Within the loop:
Simulate a roll of two dice one for the computer and one for the player with the number of sides specified earlier.
Display the results of both rolls, indicating the computer's roll and the player's roll.
Compare the computer's roll and the player's roll to determine the outcome:
If the computer's roll is greater than the player's roll, print "Computer Wins!"
If the computer's roll is less than the player's roll, print "Player Wins!"
If both rolls are equal, print "It's a draw!"
Hint! Prompt the player to decide whether they want to roll the dice again.
Start a nested while loop for input validation, which continues until a valid choice is made.
Within this loop, ask the player, "Roll again? yesno:
Accept the player's input and convert it to lowercase.
Check if the input is one of the following: 'yes', noy or n
If the input is valid, exit the input validation loop; otherwise, inform the player that the input is invalid and ask them to enter 'yes' or no
Hint! After exiting the input validation loop, check the player's choice:
If the player chooses no or n print "Thanks for Playing!" and set active to False to exit the main game loop.
If the player chooses 'yes' or y the game continues, and another round of dice rolling begins.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
