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.

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Monjawi Programming 6 10-03-2005 12:51 PM johnMG Programming 6 12-22-2004 11:05 PM RHLinuxGUY Programming 1 12-17-2004 01:32 PM Tyir Programming 2 03-28-2004 11:53 PM lugoteehalt Programming 5 10-22-2003 06:11 AM

LinuxQuestions.org

All times are GMT -5. The time now is 03:33 AM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -