Start New Discussion within our Software Development Community
#! /usr/bin/env python
import random
possible = [2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 30, 34, 50, 100]
size = int(raw_input('Please enter the size of the die you would like: '))
if size not in possible:
        print """
Please check the Wikipedia Dice article to get possible dice sizes.
I'm going to give you a standard 6 sided die to try out.
        """
        size = 6
rolltimes = int(raw_input('Please enter the number of times to roll: '))
dice = [x for x in range(1,size+1)]
rollval = []
dictionary = {}
for count in range(0,rolltimes):
        item = dice[random.randrange(len(dice))]
        dictionary[item] = dictionary.get(item,0) + 1

items = dictionary.keys()
items.sort()
for item in items:
        print "%-10s %d" % (item, dictionary[item])

How can I go about tweaking this program to roll two dice for me and notify me when I get the same number on both, then stop once it reaches its 3rd double roll, much appreciated if anyone could lend a hand!

Always use 4 space for indentations PEP 8
Here is a little help on how to trow more than one dice.

import random

possible = [2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 30, 34, 50, 100]
dice_number = int(raw_input('How many dice would you like to use: '))
size = int(raw_input('Please enter the size of the die you would like: '))

if size not in possible:
    print
    """
    Please check the Wikipedia Dice article to get possible dice sizes.
    I'm going to give you a standard 6 sided die to try out.
    """        
    size = 6
rolltimes = int(raw_input('Please enter the number of times to roll: '))
dice = [x for x in range(1,size+1)]
rollval = []
dictionary = {}
for count in range(0,rolltimes):
    for i in range(0,dice_number): 
        item = dice[random.randrange(len(dice))]
        dictionary[item] = dictionary.get(item,0) + 1

items = dictionary.keys()
items.sort()
for item in items:
    print "%-10s %d" % (item, dictionary[item])
This article has been dead for over six months. Start a new discussion instead.