Dice Rolling Simulator using Python-random

Dice Rolling Simulator using Python-random

Here's a simple dice rolling simulator using Python's random module:

import random def roll_dice(sides=6): """Roll a dice with the specified number of sides.""" return random.randint(1, sides) def main(): while True: sides = int(input("Enter the number of sides for the dice (e.g., 6 for a standard dice): ")) print(f"You rolled: {roll_dice(sides)}") another_roll = input("Do you want to roll again? (yes/no): ").lower() if another_roll != 'yes': break if __name__ == "__main__": main() 

When you run this program, it'll prompt you to specify the number of sides for the dice (e.g., 6 for a standard dice). After rolling, it'll display the result and ask if you want to roll again. Simply type "yes" to roll again or "no" to exit.


More Tags

wpf-controls xgboost usb nonblocking sections macos-high-sierra augmented-reality base-class batch-processing express-session

More Programming Guides

Other Guides

More Programming Examples