Python Forum
Dice Rolling Simulator
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dice Rolling Simulator
#1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import random
 
def roll_dice():
  """Rolls two six-sided dice and returns the sum."""
  die1 = random.randint(1, 6)
  die2 = random.randint(1, 6)
  return die1 + die2
 
def main():
  while True:
    roll = input("Would you like to roll the dice? (yes/no): ")
    if roll.lower() == "no":
      break
     
    sum = roll_dice()
    print("You rolled:", sum)
 
if __name__ == "__main__":
  main()
Can I add features like keeping track of the user's score or allowing them to choose the number of dice to roll?
buran write Oct-08-2024, 08:31 AM:
Spam link removed
buran likes this post
Reply
#2
Yes. Consider using a list for the dice values, so the number of dice is not predetermined.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  home work rolling average arcticfox286 1 45,331 Mar-02-2019, 04:55 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020