Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

I am writing a python script for synthetic division (math division shortcut ) but I can't seem to get it to work. I'm very new at this. I had originally written this on my TI - 84 plus. I am using python 2.7; Here's the script. ------------------------------ A = raw_input("Enter Constant... ") B = raw_input("Enter X... ") C = raw_input("Enter X^2... ") D = raw_input("Enter X^3... ") E = raw_input("Enter X^4... ") X = raw_input("Enter What/x?... ") print E print X*E+D print (X*E+D)*(X)+C print X(X(X*E+D)+C)+B print X(X(X(X*E+D)+C)+B)+A --------------------------- thanks!

OpenStudy (rsmith6559):

raw_input like that gives you a string value, not a numeric value. I'm not familiar with what you're trying to do, but something like this will probably come close: A = float( raw_input( "Enter Constant..." ) )

OpenStudy (anonymous):

It's a program for solving something like: (x^4-3x+5) / (x-4). Thanks! i knew it was a syntax related problem. I'll try it out now.

OpenStudy (rsmith6559):

Just to be a nuisance, Python's exponent operator is a double asterick: print 3**2 9

OpenStudy (anonymous):

I got the following error: Traceback (most recent call last): File "synthdiv.py", line 11, in <module> print X(X(X*E+D)+C)+B TypeError: 'float' object is not callable ---------------- here is the updated script: A = float(raw_input( "Enter Constant..." )) B = float(raw_input("Enter X... ")) C = float(raw_input("Enter X^2... ")) D = float(raw_input("Enter X^3... ")) E = float(raw_input("Enter X^4... ")) X = float(raw_input("Enter What/x?... ")) print E print X*E+D print (X*E+D)*(X)+C print X(X(X*E+D)+C)+B print X(X(X(X*E+D)+C)+B)+A ---------------------------------- Also, would I need to adapt the script for floating point? Would it make a difference? i Don't really understand what that is.

OpenStudy (anonymous):

The problem is that multiplication needs to be expressed using the * operator.

OpenStudy (anonymous):

For instance its not 3(4+4) its 3*(4+4)

OpenStudy (rsmith6559):

Floating point is what we call numbers that have decimals. Internally, they're stored basically as binary scientific notation called floating point. In my first reply, I could have used int() instead of float(), but I didn't know if you're user's data would have decimals. int() would truncate (chop off) the decimal. I took the chickens way out, and suggested floats.

OpenStudy (anonymous):

So C, D, and E are all X to the power of something? If that's so, then why not simplify your inputs and only ask for the value of X? The rest can be written as: C = X**2 D = X**3 E = X**4 Since the input for X would be immediately converted to float, then C, D, and E would automatically be floats.

OpenStudy (anonymous):

got it to work. Thanks a bunch guys!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!