LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 05-09-2006, 08:23 PM   #1
peter_89
Member
 
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.
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.
 
Old 05-09-2006, 08:40 PM   #2
ataraxia
Member
 
Registered: Apr 2006
Location: Pittsburgh
Distribution: Debian Sid AMD64
Posts: 296

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

Rep: Reputation: 108Reputation: 108
Code:
b = -input("Enter b: ")
or:
Code:
b = input("Enter b: ")
b = -b

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

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


Reply


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 11:51 AM
how do I do this in Python? (simple sh script) johnMG Programming 6 12-22-2004 10:05 PM
Some questions on integrating a couple simple python programs. RHLinuxGUY Programming 1 12-17-2004 12:32 PM
simple python function question Tyir Programming 2 03-28-2004 10:53 PM
Python how name variable inside a class - very simple? lugoteehalt Programming 5 10-22-2003 05:11 AM


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

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