diceroll.py

Created by tracy-pratt-1

Created on November 13, 2025

623 Bytes

Use function diceroll(n) to roll n number of dice. This function will report how many of each side is rolled.


from random import *
sides = ["1","2","3","4","5","6"]
def diceroll(n):
  ones = 0
  twos = 0
  threes = 0
  fours = 0
  fives = 0
  sixes = 0
  for i in range(n):
    result = choice(sides)
    if result == "1":
     ones += 1
    elif result == "2":
      twos += 1
    elif result == "3":
      threes += 1
    elif result == "4":
      fours += 1
    elif result == "5":
      fives += 1
    else:
     sixes += 1
  print("Ones: " + str(ones))
  print("Twos: " + str(twos))
  print("Threes: " + str(threes))
  print("Fours: " + str(fours))
  print("Fives: " + str(fives))
  print("Sixes: " + str(sixes))

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.