473,378 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

calculating the roots of ax**2+bx+c

3
hello :

This is my code :

------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. while True :
  2.     try:
  3.         ' enter the coefficients of the equation :'
  4.  
  5.         a=input('a=' )
  6.         b=input('b=' )
  7.         c=input('c=' )
  8.  
  9.         r=b**2-4*a*c
  10.         import cmath
  11.         sq=cmath.sqrt
  12.  
  13.         if r==0 :
  14.             x=(-b)/(2*a)
  15.             y=(-b)/(2*a)
  16.             print 'the roots are :',x,',',y
  17.  
  18.         elif r>0 :
  19.             x=((-b)+sq(r))/(2*a)
  20.             y=((-b)-sq(r))/(2*a)
  21.             print 'the roots are :',x,',',y
  22.  
  23.         if r<-1 :
  24.             i=sq(-1)
  25.             x=(-b+(sq(r*(i**2))))/(2*a)
  26.             y=(-b-(sq(r*(i**2))))/(2*a)
  27.             print 'the roots are :',x,',',y
  28.     except :
  29.         print 'wrong inputs , please enter numbers only'
------------------

when r<-1
################################################## ###
### the results are not like the casio calculater ###
################################################## ###
Nov 27 '12 #1

✓ answered by MR 010

I found it myself :)

i should use abs(r) :) , thanks for giving me a chance to ask you :)

2 5962
MR 010
3
I found it myself :)

i should use abs(r) :) , thanks for giving me a chance to ask you :)
Nov 27 '12 #2
bvdet
2,851 Expert Mod 2GB
MR 010 - Kudos to you for finding the issue. Thanks for the update.
Nov 30 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Ron Adam | last post by:
Hi, I'm having fun learning Python and want to say thanks to everyone here for a great programming language. Below is my first Python program (not my first program) and I'd apreciate any...
3
by: Richard Hollenbeck | last post by:
I'm sure there's a good explanation, but I haven't seen it in any of the documentation. When I query the mysql database in the user table I see two roots--one with the host as "localhost" and the...
5
by: Justin Caldicott | last post by:
Hi There are n solutions to the nth root of any number, eg: (-8)^(1/3) = 1 + sqrt(3)i or -2 or 1 - sqrt(3)i The following code:
2
by: temper3243 | last post by:
Hi, I have been trying to solve the problem Roots of the polynomial 038 from mipt.ru (el judge). I have failed to do so. I tried to search on the net but found about contour integrals for...
14
by: Protoman | last post by:
How do I write a function to calculate the nth root of a number; I'm sick of using pow() with a fractional exponent to do the job. Got any ideas on how to do this? Thanks for the help!!!
3
by: Carl Johansen | last post by:
I have a big ASP website (used by several thousand car dealers) that is a collection of lots of small and medium-sized applications. Now I want to start adding ASP.NET applications to it. I have...
2
by: =?ISO-8859-1?Q?Sch=FCle_Daniel?= | last post by:
Hello NG, given this call to roots funtion from pylab In : roots() Out: array() as far as I understand it stands for a0+a1*x+a2*x^2 in the above case it yields 2x^2+2x = 2x(1+x) and the...
1
by: candacefaye1 | last post by:
1. write a C++ program to decide if the coefficients of a quadratic equation have real roots. The three choices will be to write the message “zero divide” when A is zero, write the message “no real...
2
by: Peng Yu | last post by:
Hi, I have the following program which computes roots of a cubic function. The solution is sensitive to the type, which is due to the truncation error. 'long double T' gives three solutions, and...
2
jkmyoung
by: jkmyoung | last post by:
Calculating Large Exponents Background: This is a quick article as to how to calculate the exponents of large numbers quickly and efficiently. Starting with a basic multiplication algorithm, it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.