Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 05-09-2006, 09:23 PM   #1
Registered: Jan 2006
Distribution: Microsoft Windows XP Professional SP2; Slackware Linux 10.2
Posts: 215

Rep: Reputation: 30
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.
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.
Old 05-09-2006, 09:40 PM   #2
Registered: Apr 2006
Location: Pittsburgh
Distribution: Debian Sid AMD64
Posts: 296

Rep: Reputation: 30
Just subtract it from 0.
Old 05-10-2006, 05:23 AM   #3
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
b = -input("Enter b: ")
b = input("Enter b: ")
b = -b

Last edited by Hko; 05-10-2006 at 05:25 AM.
Old 05-10-2006, 12:13 PM   #4
Registered: Nov 2001
Posts: 75

Rep: Reputation: 15
Mathematically, all you are really doing is multiplying by -1.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie, getting simple python script to work Monjawi Programming 6 10-03-2005 12:51 PM
how do I do this in Python? (simple sh script) johnMG Programming 6 12-22-2004 11:05 PM
Some questions on integrating a couple simple python programs. RHLinuxGUY Programming 1 12-17-2004 01:32 PM
simple python function question Tyir Programming 2 03-28-2004 11:53 PM
Python how name variable inside a class - very simple? lugoteehalt Programming 5 10-22-2003 06:11 AM > Forums > Non-*NIX Forums > Programming

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration