Exilian
Exilian Projects => Computer Game Development  The Indie Alley => Nongame Programs  The Tinkers' Workshop => Topic started by: Othko97 on April 06, 2012, 10:08:02 PM

I have been creating a calculator in Python3.2, and it would mean a lot if some people tested/used it. It is not quite finished yet (I still need to let decimals be used and create some more functions). It's only text based at the moment (GUI programming disgusts me :'( ) but I think it works reasonably.
Currently you can use all the following functions:
Mathematical:
add, subtract, multiply, divide, random, root, power, factorial, percentage
Statistical:
mean, variance, standard deviation, correlation coefficient*, quartiles, IQR, sum, sum squared, mode, regression***
Fractions:
add, subtract, multiply, divide, convert, root, power
Other:
quit, funclist, help, pi, e, calc mode**
*Finds Spearman's Rank (data is automatically ranked by the program), or finds Product Moment depending on user preference
**Used to change the mode from numbers to fractions (Many functions for numbers cannot be done with fractions)
***Finds Linear regression line, a+bx
Thanks to SotK for all the help ;D
Requires Python3.2.2
[EDIT: Fixed e, pi and decimals for all the mathematical functions (apart from random.)]

It crashes when I try and type letters in to an addition (I was trying to add e and 1).

Fixed the e and pi thing, plus allowed decimals in add, subtract, multiply, divide, root and power. Going to see if I can do that to any other functions too (probably percentage).

I'm thinking of writing a module that deals with complex number calculations for FP3 revision sometime soon...

Right, so I was adding some new stats stuff into this as I finished my S1 module a bit ago, and now python is breaking on every line, saying there are syntax errors when there clearly are not any. This is my new section:
#Product Moment Correlation
def ProductMoment(list1, list2):
n = len(list1)
p = 0
sigmax = 0
sigmay = 0
sigmax2 = 0
sigmay2 = 0
sigmaxy = 0
for item in list1:
p += 1
sigmax += int(item)
sigmax2 += int(item) ** 2
sigmaxy += int(item) * int(list2[p])
for item in list2:
sigmay += int(item)
sigmay2 += int(item) ** 2
Sxx = sigmax2  (sigmax ** 2) / n
Syy = sigmay2  (sigmay ** 2) / n
Sxy = sigmaxy  (sigmax * sigmay) / n
r = str(Sxy / (sqrt((Sxx * Syy)))
return r
#Regression
def Regression(list1, list2):
n = len(list1)
p = 0
sigmax = 0
sigmay = 0
sigmax2 = 0
sigmay2 = 0
sigmaxy = 0
for item in list1:
p += 1
sigmax += int(item)
sigmax2 += int(item) ** 2
sigmaxy += int(item) * int(list2[p])
for item in list2:
sigmay += int(item)
sigmay2 += int(item) ** 2
Sxx = sigmax2  (sigmax ** 2) / n
Syy = sigmay2  (sigmay ** 2) / n
Sxy = sigmaxy  (sigmax * sigmay) / n
b = Sxy / Sxx
ybar = sigmay / n
xbar = sigmax / n
a = ybar  (b * xbar)
line = "y = " + str(b) + " x + " + str(a)
return line
For some reason "return r" caused a syntax error, despite the syntax being correct. Why?!
In addition, many other functions above this one use exactly the same syntax, yet don't throw me the same damn error!

I assume its indented properly and just not showing up the indentation in my phone right?

Scratch that, you're missing a closing bracket on the line above :)

Thank you SotK, I didn't notice that despite checking like 7 times :P

So, Correlation and Regression are added :P

For future reference, when the Python interpreter throws a syntax error on an obviously correct line then it is a syntax error on the line above, usually a missing bracket.

There will be a java release of this soon :P