Re: Program to keep track of success percentage
Musatov wrote: > I am thinking about a program where the only user input is win/loss. > > The program let's you know if you have won > more than 31% of the time or not. > > Any suggestions about how to approach authoring > such a program? Thanks. The following results are from a python toss_up program using the python random.choice module where win or lose was chosen randomly for each try for various numbers of tries For random choice of win or lose distribution seems to be very even for each result # tries win % lose % 10 50.0050.00 100 52.0048.00 1000 48.4051.60 1 49.7550.25 10 50.1749.83 100 50.0050.00 -- Stanley C. Kitching Human Being Phoenix, Arizona -- https://mail.python.org/mailman/listinfo/python-list
Re: Program to keep track of success percentage
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 script. #!env awk -f /[wW]/{ w += 1; } { printf("W: %i L: %i %i%%\n", w, NR-w, w * 100/NR); } END { 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. -tkc -- https://mail.python.org/mailman/listinfo/python-list
RE: Program to keep track of success percentage
Tim, This may be a bit awkward. I am not sure a question on the python list expects to get a one-liner, let alone in an unrelated language like AWK. Unless you install other environments like Cygwin, AWK does not tend to be available of platforms like Windows. Ditto for PERL and other languages or tools you want to use this way. There are times people appreciate something sophisticated or clever or even innovative. My personal take on this question is of someone who does not necessarily know what they need to do, let alone in python. And they did not specify how the data is supplied or whether it is a one-time thing. The two numbers needed could be supplied on the command line and gotten using argv or gotten using two input statements or read from a file or stdin. Or they could be asking for a cumulative set of wins/losses to be contiuously evaluated and as soon as the threshold of 31% is attained, print a message. OR, there could be a previously agreed upon number of games, such as 164, and you get win/loss criteria some way and you want the percentage of wins divided by the 164 to be 31%. My GUESS is they are getting a stream of win/win/loss/win/loss/... type of data, maybe one per line of text, maybe as 0 versus 1, but who knows. If we knew exactly, it might lead to trivial solutions. For example, if they had a series of 0/1 you could do a sum() and a count() and divide. But what if the scenario was to provide a score like 5 - 3 using whatever notation. Now you need to figure out if your side won and perhaps deal with ties before counting and dividing. Too many scenarios are possible but the simple answer is more like someone else said. Count the number of wins, or keep track of it. Count the total you need. Divide one by the other and compare it to 0.31 or 31 depending on your calculation method. 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%. Now that is quite possibly a way to go. But the data may not be set up that way or they may want to quit as soon as the threshold is reached or there may be blank lines or a notation for a tie. Some of those may not be one-liners. Yours would read much better if spaced out, but you might have written it this way when you were But, as mentioned, this is a python board. Would you care to do the same thing as a brief program in that language. If we had that pesky := operator, maybe. Just kidding. -Original Message- From: Python-list On Behalf Of Tim Chase Sent: Saturday, December 8, 2018 4:00 PM To: Musatov Cc: python-list@python.org Subject: Re: Program to keep track of success percentage On 2018-12-08 10:02, Musatov wrote: > I am thinking about a program where the only user input is win/loss. > The program let's you know if you have won more than 31% of the time > or not. Any suggestions about how to approach authoring such a > program? Thanks. -- Can be done with an awk one-liner: awk '/[wW]/{w+=1}{printf("W: %i L: %i %i%%\n", w, NR-w, w * 100/NR)}END{if (w * 100/NR > 31) print "More than 31% winning"}' -tkc -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Program to keep track of success percentage
On 2018-12-08 10:02, Musatov wrote: > I am thinking about a program where the only user input is > win/loss. The program let's you know if you have won more than 31% > of the time or not. Any suggestions about how to approach authoring > such a program? Thanks. -- Can be done with an awk one-liner: awk '/[wW]/{w+=1}{printf("W: %i L: %i %i%%\n", w, NR-w, w * 100/NR)}END{if (w * 100/NR > 31) print "More than 31% winning"}' -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: Program to keep track of success percentage
On Sat, Dec 8, 2018 at 1:22 PM Alister via Python-list wrote: > > On Sat, 08 Dec 2018 10:02:41 -0800, Musatov wrote: > > > I am thinking about a program where the only user input is win/loss. The > > program let's you know if you have won more than 31% of the time or not. > > Any suggestions about how to approach authoring such a program? Thanks. > > To start describe how you would do it if keeping score on paper. > > a simple loop > keep a count of the number for questions > keep a count of the number. > calculate the percentage. > > once you have what is known as pseudo code you will be 90% of the way > there > (python is effectively executable pseudo code anyway) > > this should be more than enough to help you with you homework without > doing it for you If this is not homework on the other hand, then my recommendation is to just use a spreadsheet. -- https://mail.python.org/mailman/listinfo/python-list
Program to keep track of success percentage
I am thinking about a program where the only user input is win/loss. The program let's you know if you have won more than 31% of the time or not. Any suggestions about how to approach authoring such a program? Thanks. -- https://mail.python.org/mailman/listinfo/python-list
Re: Program to keep track of success percentage
On Sat, 08 Dec 2018 10:02:41 -0800, Musatov wrote: > I am thinking about a program where the only user input is win/loss. The > program let's you know if you have won more than 31% of the time or not. > Any suggestions about how to approach authoring such a program? Thanks. To start describe how you would do it if keeping score on paper. a simple loop keep a count of the number for questions keep a count of the number. calculate the percentage. once you have what is known as pseudo code you will be 90% of the way there (python is effectively executable pseudo code anyway) this should be more than enough to help you with you homework without doing it for you -- If reporters don't know that truth is plural, they ought to be lawyers. -- Tom Wicker -- https://mail.python.org/mailman/listinfo/python-list