Python program: Simple dice rolling game program

dice rolling game program

Here’s another example of a gaming program in Python. This time, let’s create a simple dice rolling game:

import random

def roll_dice():
print(“Rolling the dice…”)
dice_value = random.randint(1, 6)
print(“The dice shows:”, dice_value)

def main():
print(“Welcome to the Dice Rolling Game!”)
print(“———————————“)

play_again = “yes”

while play_again.lower() == “yes” or play_again.lower() == “y”:
roll_dice()
play_again = input(“Roll the dice again? (yes/no): “)

print(“Thank you for playing!”)

if __name__ == ‘__main__’:
main()

In this program, the roll_dice function simulates rolling a six-sided dice. It generates a random number between 1 and 6 and displays the result.

The main function serves as the entry point of the program. It welcomes the player to the Dice Rolling Game and prompts them to roll the dice. After each roll, it asks if the player wants to roll the dice again. The game continues until the player chooses not to roll again.

When you run the program, it will display a welcome message and roll the dice. The result, showing the number rolled, will be displayed on the screen. The program will then ask if the player wants to roll the dice again. The game continues until the player chooses not to roll again.

Feel free to customize the program further by adding more features, such as keeping track of the player’s score or implementing rules for specific dice games like Yahtzee or Craps.

Top online courses in Teaching & Academics

Related Posts

Leave a Reply