Exilian

Game Design and Project Resources: The Workshops Quarter => Computer Game Development - The Indie Alley => Non-game Programs - The Tinkers' Workshop => Topic started by: Othko97 on April 06, 2012, 10:08:02 PM

Title: A Calculator
Post 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.)]
Title: Re: A Calculator
Post by: Jubal on April 06, 2012, 10:24:27 PM
It crashes when I try and type letters in to an addition (I was trying to add e and 1).
Title: Re: A Calculator
Post by: Othko97 on April 06, 2012, 10:42:41 PM
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).
Title: Re: A Calculator
Post by: Jubal on April 07, 2012, 11:11:20 PM
I'm thinking of writing a module that deals with complex number calculations for FP3 revision sometime soon...
Title: Re: A Calculator
Post by: Othko97 on December 03, 2013, 09:59:01 PM
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:

Code: [Select]
#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!
Title: Re: A Calculator
Post by: Son of the King on December 04, 2013, 09:26:19 AM
I assume its indented properly and just not showing up the indentation in my phone right?
Title: Re: A Calculator
Post by: Son of the King on December 04, 2013, 09:34:34 AM
Scratch that, you're missing a closing bracket on the line above :)
Title: Re: A Calculator
Post by: Othko97 on December 04, 2013, 08:03:53 PM
Thank you SotK, I didn't notice that despite checking like 7 times :P
Title: Re: A Calculator
Post by: Othko97 on December 04, 2013, 08:15:26 PM
So, Correlation and Regression are added :P
Title: Re: A Calculator
Post by: Son of the King on December 04, 2013, 10:37:49 PM
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.
Title: Re: A Calculator
Post by: Othko97 on February 16, 2014, 10:30:14 PM
There will be a java release of this soon :P