C PROGRAMMING ONLY PLEASE!
Please add comments so I can understand why you did certainfunctions.
This assignment requires you to solve quadratic equations using the quadratic formula. You will need to write at least three functions and apply a three-way conditional statement. Ask the user for the coefficients a, b and c of a quadratic equation ax² + b + c = 0. -b+/b²-4ac 2a Implement solving for the roots You are required to: • Write a function to determine and return the determinant b² - 4ac from the coefficients. (Hint: This function will make it easy for you to tell how many roots the equation has...) • Write a function to determine and return the first root -b+√√/b²-4ac from the coefficients. 20 • Write a function to determine and return the second root It's up to you how to put together the conditions and output from there. Submit your file as quad.py. Example runs: Enter coefficient b: 4.0 Enter coefficient c: 2.0 That quadratic has one root: -1.0 of the quadratic equation. If there is only one root, print it. If the roots are complex, print an error message. ====== === RESTART: C:/Users/matth/Desktop/quad.py ============ Enter coefficient a: 2.0 ======= ========== RESTART: C:/Users/matth/Desktop/quad.py Enter coefficient a: 2.0 Enter coefficient b: 3.0 Enter coefficient c: 2.0 Sorry, that quadratic has complex roots. ====== ========== RESTART: C:/Users/matth/Desktop/quad.py Enter coefficient a: 2.0 Enter coefficient b: 5.0 Enter coefficient c: 2.0 That quadratic has two roots: -0.5 and -2.0 ========= -b-3b²-4ac 20 ====== ======== from the coefficients. Enter coefficient a: 3.0 Enter coefficient b: 8.0 Enter coefficient c: 2.0 That quadratic has two roots: -0.2792407799438735 and -2.3874258867227933 === === ====== RESTART: C:/Users/matth/Desktop/quad.py ===================
C PROGRAMMING ONLY PLEASE! Please add comments so I can understand why you did certain functions.
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am