Dice Pairs (1) X11216


Statement
 

pdf   zip

We have been throwing a pair of dice repeatedly, recording the outcome. Each die thrown shows a number between 1 and 6. Each time, we throw both dice and record their sum. We need the so-called “histogram”: for each outcome, how many times along the experiment we have obtained that outcome.

Write a program that reads the sequence of outcomes and prints out the histogram; your program should print only the nonzero entries. Follow precisely the format in the example; there should be no additional blank spaces or lines.

Additional suggestions: (a) in Python, propose first a version using a list as internal data structure; then, move on to a version using a dict; (b) once your program works, and fully outside the jutge, find out how to depict the histograms visually using @matplotlib@. You may try asking your instructor for an example of the desired figure.

Public test cases
  • Input

    7 4 10 5 4 7 11 5 6 5 8
    

    Output

    4: 2
    5: 3
    6: 1
    7: 2
    8: 1
    10: 1
    11: 1
    
  • Information
    Author
    José Luis Balcázar
    Language
    English
    Official solutions
    Python
    User solutions
    Python