Mini Project : Rolling a Dice using Python

Dice definition and meaning | Collins English Dictionary 

In this Mini Project , we are going to create "Dice Rolling Simulator" using Python's Random Module.

Concepts used in the Code :-

  • Random
  • Integer
  • Print and f("")
  • While loop 

Code:-

import random

playAgain = "Y"    

while playAgain.upper() == "Y" or playAgain.upper() == "YES" :  

    numDice = int(input("\nHow many dice would you like to roll?  "))  
    numSides = int(input("How many sides on the dice?  "))          
    currentRolls = 0     

    while currentRolls < numDice :              

        randDice = random.randint(1,numSides)  
        currentRolls+=1                        
        print(f"Roll {currentRolls} = {randDice}")  

    playAgain = input("\nWould you like to play again?  ") 

    if playAgain.upper() != 'Y' and playAgain.upper() != 'YES':          

        input("\nThanks for playing!  Hit any key to end.") 


Demo:-



Comments

Popular Posts