Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 4 - Selections - Programming Exercises - Page 120: 4.1

Answer

The code is below.

Work Step by Step

import math a=float(input("Enter a:")) b=float(input("Enter b:")) c=float(input("Enter c:")) discriminant=(math.pow(b,2)-(4*a*c),0.5) if(discriminant>0): $ $ $ $ $ $ $ $ $ $ ans1=((b*(-1))+math.pow((math.pow(b,2)-4*a*c),0.5))/(2*a) $ $ $ $ $ $ $ $ $ $ ans2 = ((b * (-1)) - math.pow((math.pow(b, 2) - 4 * a * c), 0.5)) / (2 * a) $ $ $ $ $ $ $ $ $ $ print("The roots are {} and {} ".format(ans1,ans2)) elif(discriminant==0): $ $ $ $ $ $ $ $ ans=((b*(-1))+math.pow((math.pow(b,2)-4*a*c),0.5))/(2*a) $ $ $ $ $ $ $ $ print("the equation has one root ",ans) else: $ $ $ $ $ $ $ $ print('the equation has no real roots')
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.