LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Simple Python Question (https://www.linuxquestions.org/questions/programming-9/simple-python-question-443269/)

peter_89 05-09-2006 08:23 PM

Simple Python Question
 
I'm writing a Python app to automate the quadratic formula (not for any serious work, just for practice) and need to know how to take a number inputted from the user and make it its opposite (i.e, user inputs 15, I need to change it to negative 15). Can't find the solution anywhere from a Google search, though I imagine it's quite simple.
Code:

a = input("Enter a: ")
b = input("Enter b: ")
c = input("Enter c: ")
d = b+b**.5-(4*a*c)/(2*a)
e = b-b**.5-(4*a*c)/(2*a)
print "d=", d
print "e=", e

Basically I need to make the b variable its opposite here.

ataraxia 05-09-2006 08:40 PM

Just subtract it from 0.

Hko 05-10-2006 04:23 AM

Code:

b = -input("Enter b: ")
or:
Code:

b = input("Enter b: ")
b = -b


Vagrant 05-10-2006 11:13 AM

Mathematically, all you are really doing is multiplying by -1.


All times are GMT -5. The time now is 08:22 AM.