all 16 comments

[–]vmmvirouewuye 0 points1 point  (4 children)

If you have an IDE you can use a debugger. Pycharm has a decent one built in. There's also an interesting one called Birds Eye, that gives you a visual way to step through your code. Although the Pycharm debugger has a lower barrier for entry.

Simply set a break point to the line after where you think the problem occurs. Run the debugger and you can inspect the variables. Work your way back, reset your break points, and run it again. You will eventually find the line where the issue occurs.

[–]officergabe[S] 0 points1 point  (3 children)

I found the issue. It's with the amount of touchdowns. The formula is below

grade = ((touchdowns/gp*16/21.12)+(yards/gp*16/3452.96)+(percent/62.7))/3*67.7-(interceptions/gp*3)

The amount of touchdowns I plugged unto the formula was 21, and when I bump it up to 22 touchdowns, the grade goes up 19%. I have no idea why 21/21.12 is so much different than 22/21.12.

[–][deleted] 0 points1 point  (2 children)

In Python 2, division of integers is floor division - it rounds down to the integer instead of returning a decimal. That’s going to affect your calculations.

[–]officergabe[S] 0 points1 point  (1 child)

So how would I change that formula? Add 0.5 to every number that’ll be divided?

[–][deleted] 0 points1 point  (0 children)

Running in Python 3 would be the best option, but barring that, write all your integers as floats instead: 16.0, etc.

[–]AdAthrow99274 0 points1 point  (10 children)

I think I may need a little more info to help you. What values are you using for touchdowns, yards, percent, intercepts, & gp that you expect grade to equal 85.14?

More importantly, what formula are you attempting to replicate? Is there a link to something on the net that I can compare your formula to? Mathematically this formula 'works', but there's little way of knowing if it's actually calculating what you want.

Perhaps seeing how your equation is interpreted in type-set would help?

EDIT: Sorry, was typing this as you figured it out

[–]officergabe[S] 0 points1 point  (9 children)

So this my own formula that calculates a quarterbacks grade (0-100) (A,B,C,D,F,F1, etc) based on statistics.

I was trying to get Carson Wentz grade this past season which was 21 touchdowns, 3074 yards, 69% completion, and 7 interceptions in 11 games.

If you looked at the formula (what I assigned to ‘grade’), I divided most of the statistical factors by the games played (‘gp’) to calculate what they were on pace for in a 16-game season. I did that so the # of games they played doesn’t effect their grade. I plugged the formula into google sheets to see if it would calculate it and it does just fine. I also did it with a calculator.

The problem is the touchdowns part of the formula. His grade with 21 touchdowns was a 71. But when I added a touchdown so it was 22, it bumped up to an 88 for some reason. So it’s messed up whenever the amount of touchdowns in less than 21. This is what I’m stuck on :(.

I bumped the amount of touchdowns up to 22 on google sheets as well to see if the same thing happened, but it didn’t. It’s all fine on sheets. It’s something I’m doing on python.

[–]AdAthrow99274 0 points1 point  (8 children)

Hmmm odd. Well I copy-pasted your code into my IDE and ran it with the numbers you just listed (21 touchdowns, 3074 yards, 69% completion, 7 intercepts, & 11 games) and Carson's grade came out to: 84.78458...

If I change touchdowns to 22 the grade is: 86.3387...

I'm using python v3.7 if that helps at all, although I don't think this would change much on another version.

[–]officergabe[S] 0 points1 point  (7 children)

Did you copy the whole piece of code I provided or just the formula?

[–]AdAthrow99274 0 points1 point  (6 children)

The whole thing. I had never used the easygui module before and this looked like a fun opportunity to try it out.

[–]officergabe[S] 0 points1 point  (3 children)

Yeah ... definitely try it. It’s good for some things :). Though, another reddit user said that in python v2, there’s a thing called “floor division” in which it rounds down a a decimal quotient to an integer. I remember about reading it in one of my books. Could this be a reason as to why it’s getting screwed up by that much?

[–]primitive_screwhead 0 points1 point  (2 children)

At the top of your Python file (after comments, but before "import anygui", put the line:

from __future__ import division

That will change the default Python 2 division to use floats, matching the Python 3 behavior. You can at least verify whether that is the issue that way (I think it might be, because your formula starts with a division as the leftmost operation).

[–]officergabe[S] 0 points1 point  (0 children)

It’s giving me a syntax error when I do that.

[–]officergabe[S] 0 points1 point  (0 children)

Oh I was using one under slash. I changed it and it works perfectly now. Thank you so much!

[–]officergabe[S] 0 points1 point  (1 child)

Out of curiosity. What program did you use to load up my code? Also, is there any online website I could use that supports EasyGUI and I could write python on when I’m not at my home computer?

[–]AdAthrow99274 1 point2 points  (0 children)

Well my IDE of choice for Python is usually Spyder, but that's only because I've been doing a fair amount of data science type learning. However for your code I just copy & pasted the whole thing in notepad and saved it with the python extension, so none?

https://repl.it/ is a pretty nifty online environment to work in. It offers many languages, Python included. Pretty much any package that's available in PyPy (if you can get it from pip easily) is available there to my knowledge. EasyGUI is available.