Program to keep track of success percentage

Tim Chase python.list at
Sat Dec 8 19:09:53 EST 2018

On 2018-12-08 17:54, Avi Gross wrote:
> This may be a bit awkward.

ICWYDT. "awk"ward. :wide-eyed_gaping_grin_with_finger-guns:

You seem to have your knickers in a knot.

> Your solution in AWK assumes  lots of things. You assume the data
> is either on stdin or comes from automatically opening file names
> on the command line to generate a stream of lines. You assume a win
> is any line containing one or more lower or upper case instances of
> the letter W. You let AWK count lines and store that in NR and
> assume anything without a W is a loss. You print a running
> commentary and  only at the end of input state if they exceeded 31%.

1) yes the problem was underdefined.  If all they want is to is tally
wins ("the only user input is win/loss". Note: not blank. Not ties.
Not garbage. Not "victorias/derrotas" nor "νίκες/απώλειες"), the awk
one-liner does exactly that.  I'll grant, that the OP didn't specify
whether this was on Windows, Linux, Mac, BSD, DOS, ULTRIX, or
anything at all about the operating system.  The concepts for the
solution remain, even if awk is unavailable.  If the input isn't from
stdin it's not standard and should be specified in the problem-space
(there's a reason it's called *standard input*).

2) the problem sounded an awful lot like homework.  I'm not going to
answer a *Python* homework problem in *Python*.  I'm willing to give
the solution in another language (done) so the OP can translate
those ideas into Python.  I'm also willing to take what the OP has
already written (nothing provided in the original email) and help the
OP iterate with that.  The original request, while posted to the
Python mailing list, didn't even specify that it had to be in
Python.  If it's not homework, then the one-liner solves their
problem on any modern platform with a CLI that isn't Windows (and
even on Windows if one installs a version of awk there.)

Yes.  It could also have had a sqlite/mysql/postgres database
back-end, and command-line interface for tracking wins/losses, and a
web front-end for displaying statistics and reporting wins/losses,
and a tkinter/wx/whatever GUI for team management, and export PDFs,
and use TensorFlow for AI analysis of the results.  But that's not
what the OP asked for.

> Yours would read much better if spaced out, but you might have
> written it this way when you were 😉

While I was not in any chemically-altered state of mind, while I
penned it as one line, it would certainly be more readable as a

#!env awk -f
 w += 1;
 printf("W: %i L: %i %i%%\n", w, NR-w, w * 100/NR);
 if (w * 100/NR > 31)
  print "More than 31% winning"

There.  Happy?

> Would you care to do the same thing as a brief program in that
> language.

I can (and for the record, did), but I don't provide other people
with the prefab answers to their homework.


More information about the Python-list mailing list