Author Topic: A Calculator  (Read 2630 times)

Othko97

  • SotK Beta
  • Patrikios
    Voting Member
  • Posts: 3172
  • Karma: 9
    • View Profile
    • Awards
A Calculator
« 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.)]
« Last Edit: February 15, 2014, 02:03:32 PM by Othko97 »
Alcohol and Calculus don't mix. Never Drink and Derive.

I am Othko, the master of the 23 techniques of death, murder of the 8 popes, victor of the never ending war, he who fell from the highest of places, second of his cloning, most noble swords-bearer, Ninety-Seventh of His Name, Lord of That Bit Between High Places and Low Places Through Which One Falls In Transit Between them! Apparently, at any rate.

Jubal

  • Megadux
    Executive Officer
  • Posts: 22330
  • Karma: 101
  • Awards Awarded for oustanding services to Exilian!
    • View Profile
    • Awards
Re: A Calculator
« Reply #1 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).
The duke, the wanderer, the philosopher, the mariner, the warrior, the strategist, the storyteller, the wizard, the wayfarer...

Othko97

  • SotK Beta
  • Patrikios
    Voting Member
  • Posts: 3172
  • Karma: 9
    • View Profile
    • Awards
Re: A Calculator
« Reply #2 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).
Alcohol and Calculus don't mix. Never Drink and Derive.

I am Othko, the master of the 23 techniques of death, murder of the 8 popes, victor of the never ending war, he who fell from the highest of places, second of his cloning, most noble swords-bearer, Ninety-Seventh of His Name, Lord of That Bit Between High Places and Low Places Through Which One Falls In Transit Between them! Apparently, at any rate.

Jubal

  • Megadux
    Executive Officer
  • Posts: 22330
  • Karma: 101
  • Awards Awarded for oustanding services to Exilian!
    • View Profile
    • Awards
Re: A Calculator
« Reply #3 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...
The duke, the wanderer, the philosopher, the mariner, the warrior, the strategist, the storyteller, the wizard, the wayfarer...

Othko97

  • SotK Beta
  • Patrikios
    Voting Member
  • Posts: 3172
  • Karma: 9
    • View Profile
    • Awards
Re: A Calculator
« Reply #4 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!
Alcohol and Calculus don't mix. Never Drink and Derive.

I am Othko, the master of the 23 techniques of death, murder of the 8 popes, victor of the never ending war, he who fell from the highest of places, second of his cloning, most noble swords-bearer, Ninety-Seventh of His Name, Lord of That Bit Between High Places and Low Places Through Which One Falls In Transit Between them! Apparently, at any rate.

Son of the King

  • Technikos
    Technical Officer
  • Posts: 3240
  • Karma: 29
  • Awards Awarded for outstanding services to Exilian!
    • View Profile
    • SotK
    • Awards
Re: A Calculator
« Reply #5 on: December 04, 2013, 09:26:19 AM »
I assume its indented properly and just not showing up the indentation in my phone right?

Son of the King

  • Technikos
    Technical Officer
  • Posts: 3240
  • Karma: 29
  • Awards Awarded for outstanding services to Exilian!
    • View Profile
    • SotK
    • Awards
Re: A Calculator
« Reply #6 on: December 04, 2013, 09:34:34 AM »
Scratch that, you're missing a closing bracket on the line above :)

Othko97

  • SotK Beta
  • Patrikios
    Voting Member
  • Posts: 3172
  • Karma: 9
    • View Profile
    • Awards
Re: A Calculator
« Reply #7 on: December 04, 2013, 08:03:53 PM »
Thank you SotK, I didn't notice that despite checking like 7 times :P
Alcohol and Calculus don't mix. Never Drink and Derive.

I am Othko, the master of the 23 techniques of death, murder of the 8 popes, victor of the never ending war, he who fell from the highest of places, second of his cloning, most noble swords-bearer, Ninety-Seventh of His Name, Lord of That Bit Between High Places and Low Places Through Which One Falls In Transit Between them! Apparently, at any rate.

Othko97

  • SotK Beta
  • Patrikios
    Voting Member
  • Posts: 3172
  • Karma: 9
    • View Profile
    • Awards
Re: A Calculator
« Reply #8 on: December 04, 2013, 08:15:26 PM »
So, Correlation and Regression are added :P
Alcohol and Calculus don't mix. Never Drink and Derive.

I am Othko, the master of the 23 techniques of death, murder of the 8 popes, victor of the never ending war, he who fell from the highest of places, second of his cloning, most noble swords-bearer, Ninety-Seventh of His Name, Lord of That Bit Between High Places and Low Places Through Which One Falls In Transit Between them! Apparently, at any rate.

Son of the King

  • Technikos
    Technical Officer
  • Posts: 3240
  • Karma: 29
  • Awards Awarded for outstanding services to Exilian!
    • View Profile
    • SotK
    • Awards
Re: A Calculator
« Reply #9 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.

Othko97

  • SotK Beta
  • Patrikios
    Voting Member
  • Posts: 3172
  • Karma: 9
    • View Profile
    • Awards
Re: A Calculator
« Reply #10 on: February 16, 2014, 10:30:14 PM »
There will be a java release of this soon :P
Alcohol and Calculus don't mix. Never Drink and Derive.

I am Othko, the master of the 23 techniques of death, murder of the 8 popes, victor of the never ending war, he who fell from the highest of places, second of his cloning, most noble swords-bearer, Ninety-Seventh of His Name, Lord of That Bit Between High Places and Low Places Through Which One Falls In Transit Between them! Apparently, at any rate.