Python is a programming language that can be used to write a wide variety of programs. One such program is solving quadratic equations. If you're interested in creating a program that can solve quadratic equations, this wikiHow will guide you through the process.

Steps

  1. 1
    Install and set up Python. Visit www.python.org and download the latest version of Python for your device (Windows, macOS, Linux).
    • You will have multiple files for Python downloaded on your device. The file needed for this process is called “idle”, which the Python editor, though do not delete any other files since they are used as a reference for idle.
  2. 2
    Set up your program. Open idle from your downloaded files from python.org. You will now have the Python shell appear on your screen. On the file tab, select “New File”. Another application will open, which is the actual Python editor. On the Python editor, select “Save As” on the file tab. You can save the file as anything you prefer, such as "Solving Quadratic Equations".
  3. 3
    Import modules into Python. Many functions are not built into Python; therefore, you must import modules to run certain functions. For this program, you will need to import the math module to do basic math functions such as square roots. You do this by writing “Import math” on your Python editor.
  4. 4
    Add comments. For every program that you code, you must have comments so you and other programmers can understand what each section of code does. Without comments, programs are very hard to understand. To add comments, you write “#” and then your comment. These comments do not affect Python and are only there for the programmers to read.
  5. 5
    Add print functions. Add a print function to print text on the program so that the users can understand what this program does. You can add print functions by adding “print(“Enter Text”)” - everything in between the quotes will be printed on the screen.
  6. 6
    Add input functions for user interference. Input functions are used for Python to store data from the keyboard. For example, when the user selects a number, the input function stores this data to a variable. Therefore, the input function must be assigned to a variable. You can add an input value by writing “a = input('Enter a value:')”. This function will now store the data into the variable “a”.
  7. 7
    Begin to solve the equations. Now that all 3 values required for the quadratic equation have been entered, it can now be solved. This will require multiple parts. Also, it is wise to have the quadratic formula next to you, so you know how to set up the values. For each mathematic statement, you will equal a value such as “val1” and then use two values for the next step of the equation.
  8. 8
    Start solving the equation by powering and subtracting. The second part of the equation is “b” powered to the 2 and subtracted by 4 times “a” times “b”. Add this on the editor by writing “val2 = (b**2)-(4*a*c)”.
  9. 9
    Continue solving the equation by square rooting. The third part of the equation requires you to square root “val2”. Use the installed math module to write “val3 = math.sqrt(val2)” on the Python editor. This will square root the value found earlier on.
  10. 10
    Add. The fourth part of the equation is adding or subtracting “val3”. Since this is 2 parts, make two equations, one for adding and one for subtracting. Write “val4 = val1 + val3” and “val5 = val1 - val3” on the Python editor.
  11. 11
    Multiply. The fifth part of the equation is the bottom part of the equation, which is multiplying the value “a” by 2. Write “val6 = 2*a”.
  12. 12
    Finish solving the equation by dividing. Lastly, divide the top and bottom. Since there are 2 values because of both adding and subtracting, make 2 equations using “val4”, which is the addition part, and “val5”, which is the subtraction part. Call these values the final answer because it is the last step. Write “finalAns = val4/val6” and “finalAns2 = val5/val6”. Now you have your 2 answers.
  13. 13
    Print your values. Now that you have your 2 answers, it is time to print. You will add print statements that print out the values on the screen. Write “print(finalAns)” and “print(finalAns2)”.
  14. 14
    Run your program. You can now run the program by clicking on the “Run” tab. Python will automatically run the program on the Python shell. The program will tell the user what this program does and enter the 3 values. The users will now enter their 3 values and click enter after each value. Now the program will run and print out the precise value of your equation.

About This Article

wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, volunteer authors worked to edit and improve it over time. This article has been viewed 1,309 times.
How helpful is this?
Co-authors: 4
Updated: December 23, 2021
Views: 1,309
Categories: Python