Skip to content

Instantly share code, notes, and snippets.

@JellyWX
Created April 28, 2017 16:54
Show Gist options
  • Save JellyWX/a2eca8a8b081a733a6be2cdcdd09fe50 to your computer and use it in GitHub Desktop.
Save JellyWX/a2eca8a8b081a733a6be2cdcdd09fe50 to your computer and use it in GitHub Desktop.
A Python 3 script to solve complete the square questions and solve quadratics.
import math
print('Enter your equation, which should be in the format ax^2 + bx + c')
a = int(input('Enter the `a` value'))
b = int(input('Enter the `b` value'))
c = int(input('enter the `c` value'))
b = b/a
c = c/a
b2 = -1*(b/2)
c2 = abs(c - (b2**2))
print(str(b2) + ' +/- sqrt' + str(c2) + ' = x')
ans1 = b2 + math.sqrt(c2)
ans2 = b2 - math.sqrt(c2)
print('answers: \n' + str(ans1) + '\n' + str(ans2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment