Q:

Performing sum of dice and generating the percentage with histogram

Hi I am trying to generate a program of rolling rice and adding the resulting numbers and outputting the histogram of these sums
For example dice(trials, numbers) . If I give dice(10,5) it means that i am rolling a 5 dice 10 times.
My output should be something in this pattern:
12 : 2 : **
20 : 1 : * 
25 : 0 : 
18 : 3 : ***
19 : 0 :
10 : 0 :
14 : 1 : *
25 : 0 :
29 : 5 : *****
30 : 7 : *******

where the first column is the number (since it is 5 and the random number can be any number between 5 to 30. because if we roll a dice and sum them the minimum number we can obtain is 5 (1+1+1+1+1) and max is 30 (6+6+6+6+6). Since the trials is 10 we have 10 rows. And the second column being the number of occurrences of that number and the third being the histogram of occurences.
Can anyone please help me doing this?
I have a similar program which i am trying to modify with this..
walks(trials,steps) :
finalcount= { position :0 for position in range(-steps,steps+1)) 
for _ in range(trials): 
    finalcount[Randomwalk(steps)]+=1 
Histogram({position : round(finalcount[position]*100/trials)
           for position in finalcount})

def Randomwalk(steps): 
position=0 
for _ in range(steps): 
    direction=choice("<>") 
    if direction == "<": 
       position-=1 
    else : 
       position +=1 
return position

def Histogram(d):
keylist=sorted(d)
lo=keylist[0]
while d[lo]==0:
    lo+=1
hi=keylist[-1]
while d[hi]==0
    hi -=1
for k in range (lo,hi+1):
    print("%3i : %3i : %s" % (k,d[k],d[k]*"*"))

A:

How about this one:
from random import randint

def dice(trials, numbers):
    results = {} #createe empty dictionary
    for throw in range(trials):
        thrown = randint(1, numbers)
        try:
            results[thrown] += 1
        except:
            results[thrown] = 1
    return results

def histogram(d):
    keylist=sorted(d)
    lo=keylist[0]
    while d[lo]==0:
        lo+=1
    hi=keylist[-1]
    while d[hi]==0:
        hi -=1
    for k in range (lo,hi+1):
        print("%3i : %3i : %s" % (k,d[k],d[k]*"*"))

histogram(dice(10, 6))

If you are allowed to use counters, you can make it less clumsy:
from collections import Counter

def dice(trials, numbers):
    results = Counter()
    for throw in range(trials):
        results[randint(1, numbers)] += 1
    return results

And I just copied your histogram-code. You won't need the two while loops since only values which were thrown are added to the dictionary / counter:
def histogram(d):        
    #for k in d: #use this one if you don't want to display empty values
    for k in range(min(d), max(d)+1):  #use that one to start at the minium number thrown and display zeros for empty values
        print("%3i : %3i : %s" % (k,d[k],d[k]*"*"))

Here comes an updated version based on the comments / clarification of the question:
def mod_dice(trials, numbers):
    """A dice with 6 faces is thrown "numbers" times in each "trial"."""
    results = Counter()
    for attempt in range(trials):
        sum = 0
        for throw in range(numbers):
            sum += randint(1, 6)
        results[sum] += 1
    return results

which gives a nice plot if you start it e.g. with 500, 5:
  7 :   1 : *
  8 :   2 : **
  9 :   5 : *****
 10 :   8 : ********
 11 :  11 : ***********
 12 :  13 : *************
 13 :  28 : ****************************
 14 :  41 : *****************************************
 15 :  46 : **********************************************
 16 :  47 : ***********************************************
 17 :  45 : *********************************************
 18 :  65 : *****************************************************************
 19 :  51 : ***************************************************
 20 :  33 : *********************************
 21 :  31 : *******************************
 22 :  19 : *******************
 23 :  26 : **************************
 24 :  14 : **************
 25 :   9 : *********
 26 :   1 : *
 27 :   2 : **
 28 :   1 : *
 29 :   1 : *

