Question

Write the script code in Python 3.6 for this problem Write a program that asks a...

Write the script code in Python 3.6 for this problem

Write a program that asks a user for the 3 coefficients 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.
  • Be sure to handle the cases where some or even all of the coefficients are 0.
  • 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.
  • There could be 2 roots, 1 root, no roots, or infinite roots. If 1 or 2, you should output those. If no roots or infinite roots, you should output text stating that.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below:

print("Equation: ax^2 + bx + c ")
a=int(input("Enter a: "))
b=int(input("Enter b: "))
c=int(input("Enter c: "))
d=b**2-4*a*c
d1=d**0.5
if(a*c==0 and b==0):
print("Equation has infinite roots")
elif(a*c==0 and b!=0):
print("Equation has no roots")
elif(d<0):
print("The roots are imaginary. ")
r1=(-b+d1)/2*a
r2=(-b-d1)/2*a
print("The first root: ",r1)
print("The second root: ",r2)
else:
r1=(-b+d1)/2*a
r2=(-b-d1)/2*a
print("The first root: ",round(r1,2))
print("The second root: ",round(r2,2))

output:

Add a comment
Know the answer?
Add Answer to:
Write the script code in Python 3.6 for this problem Write a program that asks a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a script in python that inputs a line of plaintext and a distance value and...

    Write a script in python that inputs a line of plaintext and a distance value and outputs an encrypted text using a Caesar cipher. The script should work for any printable characters.

  • Write a PYTHON program that asks the user for the name of the file. The program...

    Write a PYTHON program that asks the user for the name of the file. The program should write the contents of this input file to an output file. In the output file, each line should be preceded with a line number followed by a colon. The output file will have the same name as the input filename, preceded by “ln” (for linenumbers). Be sure to use Try/except to catch all exceptions. For example, when prompted, if the user specifies “sampleprogram.py”...

  • please answer this question with python. Write a program to solve the quadratic equation ax^2 +...

    please answer this question with python. Write a program to solve the quadratic equation ax^2 + bx + c = 0 using the standard quadratic formula x = -b plusminus Squareroot b^2 - 4ac/2a or the alternative formula x = 2c/-b Squareroot b^2 - 4ac. Your program should accept values for the coefficients a, b, and c as input and produce the two roots of the equation as output. Your program should detect when the roots are imaginary, but need...

  • For Python | Instructions Write a script named difpy. This script should prompt the user for...

    For Python | Instructions Write a script named difpy. This script should prompt the user for the names of two text files and compare the contents of the two files to see if they are the same. 1. If they are the script should simply output "Yes". 2. If they are not the script should output "No", followed by the first lines of each file that differ from each other The input loop should read and compare lines from each...

  • I need the JavaScript and pseudocode for the following problem please: . Write a script that...

    I need the JavaScript and pseudocode for the following problem please: . Write a script that outputs HTML5 text that keeps displaying in the browser window the multiples of the integer 2- namely, 2, 4, 8, 16, 32, 64, etc. Your loop should not terminate (create an infinite loop). What happens when you run this script

  • 4-6 on matlab 4. Write a program in a script file that determines the real roots...

    4-6 on matlab 4. Write a program in a script file that determines the real roots of a quadratic equation ax2+bx+c 0 When the file runs, it asks the user to enter the values of the constants a, b, and c. To calculate the roots of the equation the program calculates the discriminant D, given by: D b2-4ac When D 0, the program displays message "The equation has two roots," and the roots are displayed in the next line. When...

  • Help me write a python code. Write a program that asks the user for the name...

    Help me write a python code. Write a program that asks the user for the name of a text file, then reads each line of the text file and prints it on the screen, making every other line "title case." For example, suppose the following text is saved in my_file.txt: While I nodded, nearly napping Suddenly there came a tapping As of someone gently rapping, Rapping at my chamber door. When run, the program looks like this: Enter filename: While...

  • Write a python program that does the following. a. It asks the user to enter a...

    Write a python program that does the following. a. It asks the user to enter a 5-digit integer value, n. b. The program reads a value entered by the user. If the value is not in the right range, the program should terminate. c. The program calculates and stores the 5 individual digits of n. d. The program outputs a “bar code” made of 5 lines of stars that represent the digits of the number n. For example, the following...

  • Letter Count : Write a Python script that reads a file and outputs the number of...

    Letter Count : Write a Python script that reads a file and outputs the number of words that start with each letter. This means that for every letter we want to count the total number of (nonunique) words that begin with that letter. In your implementation you should ignore the letter case, i.e., consider all words as lower case. Output the results in the following format (below values are hypothetical): a or A: 120 b or B: 460 c or...

  • Exercise 1 - Create a List to Sum Values Write a python script that sums the...

    Exercise 1 - Create a List to Sum Values Write a python script that sums the values in a list called add_list that contains the following values: (10, 2, -4, 8). Make sure you include a for loop when iterating through the list to sum the values. Take screenshots of the code and output. Exercise 2 – Create a Dictionary Write a python script that prints a dictionary where the key numbers are 1, 2, 3, 4, and 5 and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT