GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — python-dice-roller/dice_roller.py at main · aizazullahdurrani8/python-dice-roller

Expand file tree

/

dice_roller.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
41 lines (32 loc) · 1.19 KB
/

dice_roller.py

Copy path

File metadata and controls

41 lines (32 loc) · 1.19 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import random # Used for generating random numbers
def roll_dice(sides=6, rolls=1):
"""
Rolls a die with the specified number of sides, multiple times.
Parameters:
- sides (int): Number of sides on the die (default is 6)
- rolls (int): Number of times to roll the die
Returns:
- List of integers representing the results of each roll
"""
# Generate a list of random integers for each roll
results = [random.randint(1, sides) for _ in range(rolls)]
return results
def main():
print("Dice Roller")
try:
# Ask user for number of sides (e.g., 6 for standard die)
sides = int(input("Enter number of sides on the die (default 6): ") or 6)
# Ask user how many times to roll the die
rolls = int(input("How many times to roll? (default 1): ") or 1)
except ValueError:
# Handle invalid (non-integer) input
print("Please enter valid numbers.")
return
# Perform the dice rolls
results = roll_dice(sides, rolls)
# Display the results to the user
for i, result in enumerate(results, 1):
print(f"Roll {i}: {result}")
# Entry point of the script
if __name__ == "__main__":
main()
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.