# Is there any place that I can upload my code to for feedback?

I’ve been trying to solve any problems I come across on my own and to get the code up to a functioning condition before calling it ‘done’, but I am interested in getting feedback on how I could have done things differently to make the program more efficient or look better. Can I ask for feedback on Codecademy, or is there another forum aimed more towards improving finished code?

``````'''
Polynomial Secant Line Calculator
Saturday, July 21 2018
'''
from time import sleep
def start_up():
print 'Welcome to u/withdrohngeohn\'s Polynomial Secant Line Calculator\nYou can enter any degree polynomial and find a secant line through two points.'
while True:
exit()
degree = int(raw_input('Enter a number of degrees: '))
term_list = degree_finder(degree)
print 'The function is Y=',
for x in range(degree,-1,-1):
print '+ %dX^%d' % (term_list[x], x),
pt1 = float(raw_input('Enter the 1st X coordinate: '))
pt2 = float(raw_input('Enter the 2nd X coordinate: '))
print line(pt1,pt2,term_list)
def line(pt1,pt2,term_list):
fpt1 = 0
fpt2 = 0
for x in term_list:
fpt1 += term_list[x] * pt1 ** x
fpt2 += term_list[x] * pt2 ** x
slope = (fpt2 - fpt1)/(pt2 - pt1)
yint = -1 * slope * pt1 + fpt1
return 'The secant line is:\nY = %dX + %d' % (slope,yint)

def degree_finder(dgr): # creates a dictionary that stores keys (degree) for values (coefficient)
term_list = {}
if dgr < 0 or type(dgr) is not int:
print 'Wrong type or invalid degree'
whoops()
for x in range(dgr,-1,-1):
term_list[x] = float(raw_input('Enter a coefficient for the %d degree: ' % x))
if type(term_list[x]) is not float:
whoops()
return term_list
def whoops():
print 'Whoops!'
quit()
def exit():
choice = raw_input('Enter Y to continue (otherwise exit): ').upper()
if choice != 'Y':
space = ''
for x in 'SEEYOULATER':
print x + space
space+= '    '
sleep(.5)
quit()
start_up()
``````
1 Like

I suggest running flake8 on your code and changing most of what it suggests (what you might want to skip is docstrings)

I would put all the interface code separately from the math - some kind of main function that asks for input, calls the functions that does the math, and then prints the result. And rather than calling quit just break out of that loop after which there would be no more code

I wouldn’t ask to run again and instead terminate by killing the process or not providing any more input (end of file)

…after converting something to float, don’t bother testing if the resulting type is float… it is, or it failed, that check doesn’t help in either case

rather than iterating through indexes, i’d iterate through the list. if it should be reversed, create a reversed list. indexes are for when you care about which location you’re currently visiting

…any reason for using dict instead of list? I’d append to an empty list, and reverse afterwards if needed

the user probably doesn’t want the program to wait half a second before it exits

1 Like

Looking back, I have no idea why I used a dictionary. Maybe, it would be helpful to delete certain in-between values if the user inputs a coefficient of 0.

edit: Oh wait. I could just use an if statement to skip over all list values of 0. ¯\_(ツ)_/¯

1 Like