Skip to main content

Command Palette

Search for a command to run...

Dice game in python

Published
1 min read
Dice game in python
D

I love creating digital solutions

In this article you'll learn how to develop python dice game using while loop.

We're going to create two variable holding a random generated number from python.

Th game will run when the two die is equal to 6 or it'll continue running until it gets double six()

import random

while True:
    input("Press enter to play dice: ")

    die1 = random.randint(1,6)
    die2 = random.randint(1,6)

    print(f"you rolled: {die1} : {die2}")

    if die1 == die2 == 6:
        print("Congratulations. you won")
        break
    else:
        print( Sorry, roll the dice again")

Credit to my teacher Mr Atha

A

Thanks for sharing this

V
Vahid5y ago

That's cool! I have tweaked the code a bit to do another dice game in my blog :) Thanks for sharing

1
D

thanks for checking out my article

1

More from this blog

devjoseph🔥

16 posts

I'm a software engineer