Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USING PYTHON 3.7 Can you please check if everything is right in my code? And help me prevent getting ValueError: math domain error (this happened

USING PYTHON 3.7

Can you please check if everything is right in my code? And help me prevent getting ValueError: math domain error (this happened on line 24 when I entered 1,2,3 for A,B,C)?

Below are the instructions for the assignment

image text in transcribed

And Below is my code so far

print("This code finds the roots of an equation using the quadratic formula")

# Quadratic equation = Ax^2 + Bx + C # And in order to find root, one must use quadratic formula, # x = (-B +- sqrt(b^2 - (4 * A * C)))/ 2 * A # Therefore, gather values for coefficients A, B and C

import math

A = int(input("Please input value for A: ")) B = int(input("Please input value for B: ")) C = int(input("Please input value for C: ")) if A != 0: x1 = (-B + math.sqrt(B**2 - (4 * A * C))) / (2 * A) x2 = (-B - math.sqrt(B**2 - (4 * A * C))) / (2 * A) print("The 2 possible roots given the coefficients entered are", x1, "and", x2)

# Above equation is invalid for linear equation (A = 0) # Write code to solve for x when A = 0

elif (A == 0) and (B != 0): if C > 0: x = -C / B else: x = C / B print("The only possible root for B=",B, "and C=",C,"is", x)

elif (A == 0) and (B == 0) and (C != 0): print("Please enter a non-zero value for C if A and B are to remain 0")

Program 4: A quadratic equation is an equation of the form Ax2 + Bx + C = 0. A, B, and C are the coefficients of the equation, and the roots are the values of x at which the equation evaluates to 0. The well-known quadratic formula is often used to find these roots. Write a program that asks a user for the coefficients A, B, and C and outputs the roots of that equation. Be aware of the following: Be sure that your request for input and your output both have descriptive text. If the roots have an imaginary component, use i when representing the imaginary term in the output. For example, you may output "3 + 7i" as a root. Be sure to handle the cases in which any or all coefficients are equal to zero. o If A != 0, there could be 2 real distinct roots, 2 real identical roots (one root of multiplicity 2), or complex roots. o If A = 0, we are left with Bx + C = 0, a linear equation with one root. o If A = B = 0, we are left with C = 0, so if user entered a non-zero value of c, write a message to the screen indicating this error

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

Identify the types of informal reports.

Answered: 1 week ago

Question

Write messages that are used for the various stages of collection.

Answered: 1 week ago