Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #40101 > unrolled thread

How would you do this?

Started byeli m <techgeek201@gmail.com>
First post2013-02-27 19:32 -0800
Last post2013-02-27 23:52 -0700
Articles 4 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  How would you do this? eli m <techgeek201@gmail.com> - 2013-02-27 19:32 -0800
    Re: How would you do this? Dave Angel <davea@davea.name> - 2013-02-28 01:29 -0500
    Re: How would you do this? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-28 06:44 +0000
    Re: How would you do this? Michael Torrie <torriem@gmail.com> - 2013-02-27 23:52 -0700

#40101 — How would you do this?

Fromeli m <techgeek201@gmail.com>
Date2013-02-27 19:32 -0800
SubjectHow would you do this?
Message-ID<0318f314-91e5-472a-a664-054ca7ea5097@googlegroups.com>
How would you find the slope, y intercept, and slope-intercept form equation for a line in python?

[toc] | [next] | [standalone]


#40112

FromDave Angel <davea@davea.name>
Date2013-02-28 01:29 -0500
Message-ID<mailman.2638.1362032972.2939.python-list@python.org>
In reply to#40101
On 02/27/2013 10:32 PM, eli m wrote:
> How would you find the slope, y intercept, and slope-intercept form equation for a line in python?
>

First, I'd form a more complete description of the problem.  Specify 
what the overall constraints are (eg. Python version, OS portability, 
where input is to be gotten, and what the input values are to mean, how 
results are to be represented)

Then, I'd write a series of tests, especially showing both parameters 
that will work, and parameters that should give exceptions.

Then, I'd break the problem description into steps in a pseudo code 
form.  For example, maybe get the input parameters (which are they, and 
in what order) from the command line. Validate the inputs, and make sure 
an answer is possible.  Then apply this formula, and print the result. 
Apply that formula and print the result.  Apply the third formula and 
print the result.  Exit the program.

Next, I'd translate that pseudo code into actual Python statements, and 
type it into a text editor.

Then run those tests, and for each that fails, either revise the test or 
the code, depending on which is wrong.

If you run into trouble on one of these steps, show us your work, and 
somebody will undoubtedly be able to help there.

-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#40115

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-02-28 06:44 +0000
Message-ID<512efce9$0$30001$c3e8da3$5496439d@news.astraweb.com>
In reply to#40101
On Wed, 27 Feb 2013 19:32:40 -0800, eli m wrote:

> How would you find the slope, y intercept, and slope-intercept form
> equation for a line in python?

I would post a message to a Python forum and ask a vague question that 
gives no detail about the problem, and hope somebody answers.

But if I actually wanted an answer, I'd give the post a sensible subject 
line, and make an effort to explain my actual problem. For instance:

"I have an equation written as a string, like '2y - 6x + 3 = 0'. How 
should I parse the string to extract the slope and intercept from the 
equation, and re-write it in the form 'y = mx+c'?"

Or:

"I have a bitmap image of a line graph. How do I detect the lines in the 
image, decide which ones are the axes, and determine the slope and 
intercept of the plotted line?"

Or:

"How do I get the slope and intercept of a Line object from the 
FancyLinearAlegbra module I downloaded from http://some-random-place-on-
the-internet.com?"

Or:

"Can somebody google the formula for slope and intercept of a line for 
me, 'cos I can't be bothered."


The answers you get will depend on which question you actually ask.



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#40116

FromMichael Torrie <torriem@gmail.com>
Date2013-02-27 23:52 -0700
Message-ID<mailman.2641.1362034371.2939.python-list@python.org>
In reply to#40101
On 02/27/2013 08:32 PM, eli m wrote:
> How would you find the slope, y intercept, and slope-intercept form
> equation for a line in python?

Well, how do you do it by hand?  Once you have the basic formula or
algorithm down, just translate it into python.  Math is math.  We can
answer specific questions of course.  Like, how would I represent the
equation in python?  Well put each term in a variable.  For example,
3x^2-2x+4 = 0, you would store the 3, 2, and 4 in variables.  Then run
your formula on them.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web