I report a simple script in Python, about second-degree equation solving. 

import math

print("Second-degree equation solving: ax^2+bx+c=0")
a = float(input("Insert a= "))
b = float(input("Insert b= "))
c = float(input("Insert c= "))

delta=b*b-4*a*c
print()
print("Discriminant= " + str(delta))
if (delta >= 0):
  x1=(-b+math.sqrt(delta))/(2*a)
  x2=(-b-math.sqrt(delta))/(2*a)
  print("Solutions are:")
  print("x1= " + str(x1))
  print("x2= " + str(x2))
else:
  print("Impossible! Roots are imaginary")

You can download Python from https://www.python.org/downloads/ and install it on a Windows PC, Linux or Mac. It is an interpreted programming language, this means that as a developer you write Python (.py) files in a text editor and then put those files into the python interpreter to be executed. The way to run a Python file is open command line of your computer, navigate to the directory where you saved your file, and run. On a Windows PC you can use the Command Line (cmd.exe): C:\Users\Your Name>python helloworld.py or you can use a Python Shell.
For example I can load this script into my Numworks calculator and use it in class.

numworks 01.jpg

A further application in Python solves both first degree and second degree equations:

import math

print("Second-degree equation solving: ax^2+bx+c=0")
print("First-degree equation solving (choose a=0): bx+c=0")
a = float(input("Insert a= "))
b = float(input("Insert b= "))
c = float(input("Insert c= "))

delta=b*b-4*a*c
print()
  if (a==0):
    if(c==0):
       print("Indeterminate solution!")
    else:
       if (b==0):
           print("Impossible!")
       else:
           x= -c/b
           print("Solution is:")
           print("x= " + str(x))
  else:
     print("Discriminant= " + str(delta))
     if (delta >= 0):
        x1=(-b+math.sqrt(delta))/(2*a)
        x2=(-b-math.sqrt(delta))/(2*a)
        print("Solutions are:")
        print("x1= " + str(x1))
        print("x2= " + str(x2))
     else:
        print("Impossible! Roots are imaginary")

Advertising

Advertising

Advertising