Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
slope intercept form
#1
Hi,

I am working on trying to write a program to convert any form of the slope intercept equation into the standard, y=mx+b form. I always have a hard time keeping track of negative an positive values and want to be able to have the computer do some of the conversion. I am wondering what you link of my code so far?

 # y = mx+b
slopeintercept = ['y', 'm','x','b']
print(slopeintercept)
print(slopeintercept[0])
message = f'{slopeintercept[0]}={slopeintercept[1]}{slopeintercept[2]}+{slopeintercept[3]}'
print(message)   
Output:
['y', 'm', 'x', 'b'] y y=mx+b [Finished in 0.3s]
Reply
#2
I don't really see the point in the current code you have. It looks like your goal is to take in a linear function that the user gives the program, and it will rearrange it to be graphed as x being the input and y the output. So basically solving for y in relation to x. The current code is hard coded, and doesn't do anything, to progress towards your goal I'd like to give some suggestions on how you could build the program. First you should create a part of the program to take in user input. Look into string.strip and string.lower as I think they'd be useful for simplifying the equation to be examined. So then the equation can be passed to the part of the program which is to rearrange the program. Think about how you yourself solve do this, and translate that into code.
A couple hints if you want them: Try separating my operators (+, -, /, etc.). Sorting the equation into parts such as constants and variables.
Hope this helps!
Reply
#3
Maybe you need the eval() function.
Reply
#4
(Jun-14-2020, 08:36 AM)ibreeden Wrote: Maybe you need the eval() function.
what they will need the eval() for? Not to mention it's really dangerous to pass untrusted user input to eval
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Hi Buran,
I am not sure what Dasiey exactly wants but I see he is deriving a formula. And my guess is he wants to evaluate that formula with a range of values for the variables. Then eval() could do the job.
You are very right about the warning to check untrusted user input.
Reply
#6
I will look into the eval(). I am honestly thinking how many combinations are there of the equation y=mx+b?

I think it is like a binomial distribution. y can be + or -, mx can be + or -, and b can be +or -. The user should be able to write the equation any way they want.

If I can take the user input in any way it is presented then convert it to the slope intercept, y=mx+b form that would be helpful.

May be I can store all the possible combinations in a list. Walk through the list and if the input matches one of the combinations then the standard form can be output.
Reply
#7
The only way a linear equation can be changed is a stretch horizontally and/or vertically and an offset on the x and/or y axis. Storing a bunch of different forms would be inefficient, it would be much better to use an algorithm rather than something hard-coded. Think of an algorithm or method that you would use to do this. It often helps to make a program think and work the same way we would, cause then it's basically a human that can perform tasks very quickly.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem about slope in python script for bitcoin trading fisher_garry 1 2,495 Sep-02-2020, 01:39 PM
Last Post: fisher_garry
  How to intercept python method calls? DineshBhat 0 2,491 Jul-15-2019, 03:46 AM
Last Post: DineshBhat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020