I have written a program that can convert a Quadratic equation written in standard form to vertex form. I am a beginner in Python and coding in general. I have posted programs on StackOverflow before but have received a lot of criticism towards them. I am trying to improve upon my skills as a coder and I am wondering if there is any way I can shorter/simplify or just overall improve this program I have written? Thanks in advance!
'''
Standard Form to Vertex Form Converter
Created by Patrick Thomas
'''
#Preliminary Information--------------------------------------------------------
import time
time.sleep(0.5)
print('Standard Form to Vertex Form Converter')
time.sleep(0.5)
goAgain = True
#greatest common divisor funct
def gcd(num, den):
if int(den) == 0:
return int(num)
return gcd(int(den), int(num) % int(den))
#While Loop---------------------------------------------------------------------
while goAgain == True:
#input
time.sleep(0.5)
print('---------------------')
print('ax² + bx + c')
print('---------------------')
a = int(input('a = '))
b = int(input('b = '))
c = int(input('c = '))
print('')
#h calculation
two_a = 2 * a // gcd(2 * a, -b % 2 * a)
neg_b = -b // gcd(2 * a, -b % 2 * a)
#y-int calculation
yInt = a * 0 ** 2 + b * 0 + c
#k calculation
bSquared = b ** 2 // gcd(b ** 2, 4 * a)
four_a = 4 * a // gcd(b ** 2, 4 * a)
#other variables
hNumerator = neg_b
hDenomator = two_a
kNumerator = c * four_a - bSquared
kDenomator = four_a
h = neg_b
k = c * four_a - bSquared
hReverse = neg_b * -1
kNeg = c * four_a - bSquared * -1
#output
if hDenomator == 1 and kDenomator == 1:
if a == 1:
if k >= 0:
if hReverse >= 0:
print('f(x) = (x + {})² + {}'.format(int(hReverse),int(k)))
print('Vertex = ({},{})'.format(int(h),int(k)))
print('Axis of Sym = {}'.format(int(h)))
elif hReverse < 0:
print('f(x) = (x - {})² + {}'.format(int(h),int(k)))
print('Vertex = ({},{})'.format(int(h),int(k)))
print('Axis of Sym = {}'.format(int(h)))
elif k < 0:
if hReverse >= 0:
print('f(x) = (x + {})² - {}'.format(int(hReverse),int(kNeg)))
print('Vertex = ({},{})'.format(int(h),int(k)))
print('Axis of Sym = {}'.format(int(h)))
elif hReverse < 0:
print('f(x) = (x - {})² - {}'.format(int(h),int(kNeg)))
print('Vertex = ({},{})'.format(int(h),int(k)))
print('Axis of Sym = {}'.format(int(h)))
elif a == -1:
if k > 0:
if hReverse >= 0:
print('f(x) = -(x + {})² + {}'.format(int(hReverse),int(k)))
print('Vertex = ({},{})'.format(int(h),int(k)))
print('Axis of Sym = {}'.format(int(h)))
elif hReverse < 0:
print('f(x) = -(x - {})² + {}'.format(int(h),int(k)))
print('Vertex = ({},{})'.format(int(h),int(k)))
print('Axis of Sym = {}'.format(int(h)))
elif k < 0:
if hReverse >= 0:
print('f(x) = -(x + {})² - {}'.format(int(hReverse),int(kNeg)))
print('Vertex = ({},{})'.format(int(h),int(k)))
print('Axis of Sym = {}'.format(int(h)))
elif hReverse < 0:
print('f(x) = -(x - {})² - {}'.format(int(h),int(kNeg)))
print('Vertex = ({},{})'.format(int(h),int(k)))
print('Axis of Sym = {}'.format(int(h)))
else:
if k >= 0:
if hReverse >= 0:
print('f(x) = {}(x + {})² + {}'.format(a,int(hReverse),int(k)))
print('Vertex = ({},{})'.format(int(h),int(k)))
print('Axis of Sym = {}'.format(int(h)))
elif hReverse < 0:
print('f(x) = {}(x - {})² + {}'.format(a,int(h),int(k)))
print('Vertex = ({},{})'.format(int(h),int(k)))
print('Axis of Sym = {}'.format(int(h)))
elif k < 0:
if hReverse >= 0:
print('f(x) = {}(x + {})² - {}'.format(a,int(hReverse),int(kNeg)))
print('Vertex = ({},{})'.format(int(h),int(k)))
print('Axis of Sym = {}'.format(int(h)))
elif hReverse < 0:
print('f(x) = {}(x - {})² - {}'.format(a,int(h),int(kNeg)))
print('Vertex = ({},{})'.format(int(h),int(k)))
print('Axis of Sym = {}'.format(int(h)))
elif hDenomator > 1 and kDenomator > 1:
if a == 1:
if k >= 0:
if hReverse >= 0:
print('f(x) = (x + {}/{})² + {}/{}'.format(int(hReverse),int(hDenomator),int(kNumerator),int(kDenomator)))
print('Vertex = ({}/{},{}/{})'.format(int(hNumerator),int(hDenomator),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
elif hReverse < 0:
print('f(x) = (x - {}/{})² + {}/{}'.format(int(hNumerator),int(hDenomator),int(kNumerator),int(kDenomator)))
print('Vertex = ({}/{},{}/{})'.format(int(hNumerator),int(hDenomator),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
elif k < 0:
if hReverse >= 0:
print('f(x) = (x + {}/{})² - {}/{}'.format(int(hReverse),int(hDenomator),int(kNeg),int(kDenomator)))
print('Vertex = ({}/{},{}/{})'.format(int(hNumerator),int(hDenomator),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator),int(kNumerator),int(kDenomator)))
elif hReverse < 0:
print('f(x) = (x - {}/{})² - {}/{}'.format(int(hNumerator),int(hDenomator),int(kNeg),int(kDenomator)))
print('Vertex = ({}/{},{}/{})'.format(int(hNumerator),int(hDenomator),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
elif a == -1:
if k >= 0:
if hReverse >= 0:
print('f(x) = -(x + {}/{})² + {}/{}'.format(int(hReverse),int(k)))
print('Vertex = ({}/{},{}/{})'.format(int(h),int(k)))
print('Axis of Sym = {}/{}'.format(int(h)))
elif hReverse < 0:
print('f(x) = -(x - {}/{})² + {}/{}'.format(int(h),int(k)))
print('Vertex = ({}/{},{}/{})'.format(int(h),int(k)))
print('Axis of Sym = {}/{}'.format(int(h)))
elif k < 0:
if hReverse >= 0:
print('f(x) = -(x + {}/{})² - {}/{}'.format(int(hReverse),int(hDenomator),int(kNeg),int))
print('Vertex = ({}/{},{}/{})'.format(int(hNumerator),int(hDenomator),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
elif hReverse < 0:
print('f(x) = -(x - {}/{})² - {}/{}'.format(int(hNumerator),int(hDenomator),int(kNeg),int(kDenomator)))
print('Vertex = ({}/{},{}/{})'.format(int(hNumerator),int(hDenomator),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
else:
if k >= 0:
if hReverse >= 0:
print('f(x) = {}(x + {}/{})² + {}/{}'.format(a,int(hReverse),int(hDenomator),int(kNumerator),int(kDenomator)))
print('Vertex = ({}/{},{}/{})'.format(int(hNumerator),int(hDenomator),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
elif hReverse < 0:
print('f(x) = {}(x - {}/{})² + {}/{}'.format(a,int(hNumerator),int(hDenomator),int(kNumerator),int(kDenomator)))
print('Vertex = ({}/{},{}/{})'.format(int(hNumerator),int(hDenomator),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
elif k < 0:
if hReverse >= 0:
print('f(x) = {}(x + {}/{})² - {}/{}'.format(a,int(hReverse),int(hDenomator),int(kNeg),int(kDenomator)))
print('Vertex = ({}/{},{}/{})'.format(int(hNumerator),int(hDenomator),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
elif hReverse < 0:
print('f(x) = {}(x - {}/{})² - {}/{}'.format(a,int(hNumerator),int(hDenomator),int(kNeg),int(kDenomator)))
print('Vertex = ({}/{},{}/{})'.format(int(hNumerator),int(hDenomator),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
elif hDenomator > 1 and kDenomator == 1:
if a == 1:
if k >= 0:
if hReverse >= 0:
print('f(x) = (x + {}/{})² + {}'.format(int(hReverse),int(hDenomator),int(k)))
print('Vertex = ({}/{},{})'.format(int(hNumerator),int(hDenomator),int(k)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
elif hReverse < 0:
print('f(x) = (x - {}/{})² + {}'.format(int(hNumerator),int(hDenomator),int(k)))
print('Vertex = ({}/{},{})'.format(int(hNumerator),int(hDenomator),int(k)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
elif k < 0:
if hReverse >= 0:
print('f(x) = (x + {}/{})² - {}'.format(int(hReverse),int(hDenomator),int(kNeg)))
print('Vertex = ({}/{},{})'.format(int(hNumerator),int(hDenomator),int(k)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
elif hReverse < 0:
print('f(x) = (x - {}/{})² - {}'.format(int(hNumerator),int(hDenomator),int(kNeg)))
print('Vertex = ({}/{},{})'.format(int(hNumerator),int(hDenomator),int(k)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
elif a == -1:
if k >= 0:
if hReverse >= 0:
print('f(x) = -(x + {}/{})² + {}'.format(int(hReverse),int(hDenomator),int(k)))
print('Vertex = ({}/{},{})'.format(int(hNumerator),int(hDenomator),int(k)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),hDenomator))
elif hReverse < 0:
print('f(x) = -(x - {}/{})² + {}'.format(int(hNumerator),int(hDenomator),int(k)))
print('Vertex = ({}/{},{})'.format(int(hNumerator),int(hDenomator),int(k)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
elif k < 0:
if hReverse >= 0:
print('f(x) = -(x + {}/{})² - {}'.format(int(hReverse),int(hDenomator),int(kNeg)))
print('Vertex = ({}/{},{})'.format(int(hNumerator),int(hDenomator),int(k)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
elif hReverse < 0:
print('f(x) = -(x - {}/{})² - {}'.format(int(hNumerator),int(hDenomator),int(kNeg)))
print('Vertex = ({}/{},{})'.format(int(hNumerator),int(hDenomator),int(k)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
else:
if k >= 0:
if hReverse >= 0:
print('f(x) = {}(x + {}/{})² + {}'.format(a,int(hReverse),int(hDenomator),int(k)))
print('Vertex = ({}/{},{})'.format(int(hNumerator),int(hDenomator),int(k)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
elif hReverse < 0:
print('f(x) = {}(x - {}/{})² + {}'.format(a,int(hNumerator),int(hDenomator),int(k)))
print('Vertex = ({}/{},{})'.format(int(hNumerator),int(hDenomator),int(k)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
elif k < 0:
if hReverse >= 0:
print('f(x) = {}(x + {}/{})² - {}'.format(a,int(hReverse),int(hDenomator),int(kNeg)))
print('Vertex = ({}/{},{})'.format(int(hNumerator),int(hDenomator),int(k)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
elif hReverse < 0:
print('f(x) = {}(x - {}/{})² - {}'.format(a,int(hNumerator),int(hDenomator),int(kNeg)))
print('Vertex = ({}/{},{})'.format(int(hNumerator),int(hDenomator),int(k)))
print('Axis of Sym = {}/{}'.format(int(hNumerator),int(hDenomator)))
elif hDenomator == 1 and kDenomator > 1:
if a == 1:
if k >= 0:
if hReverse >= 0:
print('f(x) = (x + {})² + {}/{}'.format(int(hReverse),int(kNumerator),int(kDenomator)))
print('Vertex = ({},{}/{})'.format(int(h),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}'.format(int(h)))
elif hReverse < 0:
print('f(x) = (x - {})² + {}/{}'.format(int(h),int(kNumerator),int(kDenomator)))
print('Vertex = ({},{}/{})'.format(int(h),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}'.format(int(h)))
elif k < 0:
if hReverse >= 0:
print('f(x) = (x + {})² - {}/{}'.format(int(hReverse),int(kNeg),int(kDenomator)))
print('Vertex = ({},{})'.format(int(h),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}'.format(int(h)))
elif hReverse < 0:
print('f(x) = (x - {})² - {}/{}'.format(int(h),int(kNeg),int(kDenomator)))
print('Vertex = ({},{}/{})'.format(int(h),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}'.format(int(h)))
elif a == -1:
if k >= 0:
if hReverse >= 0:
print('f(x) = -(x + {})² + {}/{}'.format(int(hReverse),int(kNumerator),int(kDenomator)))
print('Vertex = ({},{}/{})'.format(int(h),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}'.format(int(h)))
elif hReverse < 0:
print('f(x) = -(x - {})² + {}/{}'.format(int(h),int(kNumerator),int(kDenomator)))
print('Vertex = ({},{}/{})'.format(int(h),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}'.format(int(h)))
elif k < 0:
if hReverse >= 0:
print('f(x) = -(x + {})² - {}/{}'.format(int(hReverse),int(kNeg)))
print('Vertex = ({},{}/{})'.format(int(h),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}'.format(int(h)))
elif hReverse < 0:
print('f(x) = -(x - {})² - {}/{}'.format(int(h),int(kNeg),int(kDenomator)))
print('Vertex = ({},{}/{})'.format(int(h),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}'.format(int(h)))
else:
if k >= 0:
if hReverse >= 0:
print('f(x) = {}(x + {})² + {}/{}'.format(a,int(hReverse),int(kNumerator),int(kDenomator)))
print('Vertex = ({},{}/{})'.format(int(h),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}'.format(int(h)))
elif hReverse < 0:
print('f(x) = {}(x - {})² + {}/{}'.format(a,int(h),int(kNumerator),int(kDenomator)))
print('Vertex = ({},{}/{})'.format(int(h),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}'.format(int(h)))
elif k < 0:
if hReverse >= 0:
print('f(x) = {}(x + {})² - {}/{}'.format(a,int(hReverse),int(kNeg),int(kDenomator)))
print('Vertex = ({},{}/{})'.format(int(h),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}'.format(int(h)))
elif hReverse < 0:
print('f(x) = {}(x - {})² - {}/{}'.format(a,int(h),int(kNeg),int(kDenomator)))
print('Vertex = ({},{}/{})'.format(int(h),int(kNumerator),int(kDenomator)))
print('Axis of Sym = {}'.format(int(h)))
#End of Program-----------------------------------------------------------------