Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Dice script

brento73brento73 Member Posts: 4
I'm sure this is simple, but I can't seem to find the solution. What I need is to roll a number of dice(that part I've got down), but to ignore the lowest roll before totalling the rolls.

For instance 3, 5, 6 would be 11, since 3 is ignored

Thanks in advance,

brento73

Comments

  • infidelinfidel Member Posts: 2,900
    : I'm sure this is simple, but I can't seem to find the solution. What I need is to roll a number of dice(that part I've got down), but to ignore the lowest roll before totalling the rolls.

    My first thought was to store your individual rolls in a list, then write a function like:

    [code]
    def SumListExcludeLowest(L):
    L.sort()
    total = 0
    for num in L[1:]:
    total += num
    return total

    if __name__ == '__main__':
    print SumListExcludeLowest([4,2,5,1])
    [/code]

    This just uses the builtin list.sort() method which orders the values, then you iterate through all list elements after the first one. Piece of cake.
  • Justin BibJustin Bib USAMember Posts: 0

    ____ / http://forcoder.org / free ebooks and video tutorials about \ Java JavaScript Visual Basic .NET PHP Perl Go Visual Basic PL/SQL Ruby C++ Swift Assembly Python Objective-C Scratch C MATLAB Delphi R C# FoxPro ML Scheme Prolog LabVIEW Apex D Julia Awk Transact-SQL F# Alice Bash Rust Hack VBScript Ada Erlang Fortran Lisp Dart COBOL SAS Logo Kotlin Scala Crystal Lua ABAP Clojure \ _______

Sign In or Register to comment.