Go Job Hunting at the LQ Job Marketplace
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org Simple Python Question
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

Notices

 05-09-2006, 09:23 PM #1 peter_89 Member   Registered: Jan 2006 Distribution: Microsoft Windows XP Professional SP2; Slackware Linux 10.2 Posts: 215 Rep: 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.
 05-09-2006, 09:40 PM #2 ataraxia Member   Registered: Apr 2006 Location: Pittsburgh Distribution: Debian Sid AMD64 Posts: 296 Rep: Just subtract it from 0.
 05-10-2006, 05:23 AM #3 Hko Senior Member   Registered: Aug 2002 Location: Groningen, The Netherlands Distribution: ubuntu Posts: 2,530 Rep: Code: `b = -input("Enter b: ")` or: Code: ```b = input("Enter b: ") b = -b``` Last edited by Hko; 05-10-2006 at 05:25 AM.
 05-10-2006, 12:13 PM #4 Vagrant Member   Registered: Nov 2001 Posts: 75 Rep: Mathematically, all you are really doing is multiplying by -1.