Dice throwing game variable players and throws

TrustyTony 0 Tallied Votes 739 Views Share

I wrote this as reaction for Pascal newbie's question in Pascal Delphi forum.

import random

# get Python 2 to use Python 3 style input
    input = raw_input

def number_of_things(thing='turns'):
    while True:
            return int(input('Give number of %s decided: ' % thing))
        except ValueError:
            print('Please enter integer value')
def throws(times=1, players=2):
    return [[random.randint(1,6) for count in range(times)] for playercount in range(players)]

def show_n_players(number_of_players=2):
    game = throws(number_of_things(), number_of_players)
    for number, got in enumerate(game, 1):
        print('Player %i: throws: %s, sum %i' % (number, got, sum(got)))
    print(('Winner was player %i' %
           max((sum(got), no)
               for no, got in enumerate(game, 1))[1]).center(
                   60, '*'))

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.