Have you ever play dice rolling game with someone ?

     Maybe some of us still play it, but I used to play this game with my friends when I was a kid. Now my friend here will be the computer. So let's get started right away. By the way, you can develop without installing Python on your computer. One of the online Python code editors is here. 

   I will import Random Library to make a choice random numbers between 1 and 6 . I will create two array variables.Those variables will keep the numbers of the computer and my own dice.


import random 

diceComputer=[1,2,3,4,5,6]
diceMe=[1,2,3,4,5,6] 


   I will create some variables to show game statistics at the end of the game.

 win=0
lose=0
draw=0
counter=0
   

 


     Now I determine how many times I will play the game with a While loop. I will also show the win,lose,draw statistics in here. In the meantime ,I shuffle the numbers I keep in the array with the shuffle function. Then I choose a random number from the variable I keep in the array. And I compare my own choice with the computer's choice. Depending on the result ,I increase my statistical variables one by one.

 

 

 while counter<3:
    random.shuffle(diceComputer)
    random.shuffle(diceMe)
    me=random.choice(diceMe)
    computer=random.choice(diceComputer)
    print('Computer Dice :' + str(computer)+' Benim Zar: '+str(me))
    if computer>me:
        print('You Lose the Game')
        lose=lose+1
    elif computer<me:
        print('You Win The Game')
        win=win+1
    else:
        print('Draw')
        draw=draw+1 

  counter=counter+1 

print('***********************************************************')
print('Win :' + str(win) +'Lose :'+ str(lose)+' Draw:'+ str(draw)) 


    When we combine the all codes it will look like this.

 

 

   Finally, when we compile the program, the output we will get will be as follows. You can also download the source codes of this program from here.