Giter Club home page Giter Club logo

calculator's Introduction

Calculator

A scientific calculator on the computer

Users

Users can run the following files:

  • 'UserInterface.pyw' for a graphical user interface
  • 'Interface.py' for a command-line interface with memory
  • 'Calc.py' for a command-line interface without memory

Programmers

To calculate the answer to a single expression

Use the 'calculate' function from the file 'Calc.py'

To create a custom user interface using my memory system

Instantiate the 'Interface' class in the file 'Interface.py' and:

  • if the user wants to calculate the answer to an expression, use the 'calculate' method
  • if the user wants to view instructions, use the 'instructions' attribute
  • if the user wants to view memory, use the 'recent_memory' method
  • if the user wants to clear memory, use the 'clear_memory' method
  • if the user wants to insert a specific memory answer into their expression:
    1. get which memory item is being requested
    2. use the 'memory_item' method to get the original expression and answer of interest
    3. it may be best to re-calculate the answer using the original expression and the 'calculate' method
    4. insert the answer from memory or the re-calculated answer into the expression

NOTE: before calling the 'recent_memory' or 'memory_item' methods with a number from the user, the interface should call 'len_memory' to check how many items are in memory and verify the number wanted is a valid number and equal to or less than the number of items in memory. If not, display the relevant error message. If either of these methods are called with invalid parameters, they will raise 'IndexError'.

To create a custom user interface without my memory system

  1. use the 'calculate' function in 'Calc.py' to call the calculator with an expression
  2. catch any errors derived from 'CalcError' in 'Errors.py' and present the message to the user
  3. add to and present to the user the instructions from the global variable 'instructions' in 'Calc.py'

To add custom operations to the calculator

  1. write a function to execute the operation in 'Operations.py'
  2. import this into 'Datatypes.py'
  3. add details of the operation including the function to the 'valid_tokens' dictionary at the bottom of 'Datatypes.py'
  4. explain how to use it in 'Instructions.txt'

Instructions

Enter an expression to calculate the answer.

Operators are represented by a symbol and perform an operation on the numbers around them. Binary operators have 2 numbers (1 either side of the symbol), whereas unary operators have 1 number (either left or right of the symbol). Functions are represented by a word followed by brackets containing all operands (values needed for the function) separated by commas. Constants are a word representing a number very accurately. Simply enter the word and it will convert it to the number.

Functions and constants are always executed first and then operators are executed using BODMAS - brackets, other (exponents and unary operators), division and multiplication, addition and subtraction.

Binary Operators

  • Addition: use '+' between 2 numbers to find the first add the second.
  • Subtraction: use '-' between 2 numbers to find the first subtract the second.
  • Multiplication: use '*' between 2 numbers to find the first multiplied by the second.
  • Division (true): use '/' between 2 numbers to find the first divided by the second.
  • Division (floor): use '\' between 2 numbers to find the first divided by the second and rounded down to the nearest whole number.
  • Mod: use '%' between 2 numbers to find the remainder after the first is divided by the second.
  • Exponentiation: use '^' between 2 numbers to find the first to the power of the second.
  • Root: use '¬' to find the first th root of the second - '2¬a' is the square root of 'a', '3¬a' is the cube root of 'a', etc.
  • Permutations: use 'P' to find the number of ways there are to organise the second number of items into the first number of places including all possible orders.
  • Combinations: use 'C' to find the number of ways there are to organise the second number of items into the first number of places only counting 1 possible order.

Unary Operators

  • Positive: use '+' before a number to find the positive of it.
  • Negative: use '-' before a number to find the negative of it.
  • Factorial: use '!' after a positive whole number to find the product of all positive whole numbers less than or equal to it.

Functions

  • Natural log: use 'ln' with 1 operand to find the natural logarithm of it.
  • Logarithm: use 'log' with 2 operands to find the logarithm of the first to the second base.
  • Absolute value: use 'abs' with 1 operand to find the absolute value of it which is always positive.
  • Lowest common multiple: use 'lcm' with 2 operands to find the lowest common multiple of them.
  • Highest common factor: use 'hcf' with 2 operands to find the highest common factor of them.
  • Random number generator: use 'rand' with 2 operands to find a random integer between them, inclusive.
  • Quadratic equation solver: use 'quadp' with 3 operands (a, b and c) to find the positive square root answer to the quadratic equation 'ax^2 + bx + c = 0' or use 'quadn' to find the negative square root answer of the same equation.
  • Sine: use 'sin' with 1 operand (an angle) to find the ratio between the opposite side and hypotenuse of its triangle.
  • Cosine: use 'cos' with 1 operand (an angle) to find the ratio between the adjacent side and hypotenuse of its triangle.
  • Tangent: use 'tan' with 1 operand (an angle) to find the radio between the opposite and adjacent sides of its triangle.
  • Inverse sine: use 'arsin' with 1 operand between -1 and 1 inclusive to find the angle it makes with the opposite side and hypotenuse of its triangle.
  • Inverse cosine: use 'arcos' with 1 operand between -1 and 1 inclusive to find the angle it makes with the adjacent side and hypotenuse of its triangle.
  • Inverse tangent: use 'artan' with 1 operand to find the angle it makes with the opposite and adjacent sides of its triangle.
  • Hyperbolic sine: use 'sinh' with 1 operand (an angle) to find the ratio between the opposite side and hypotenuse of its hyperbola.
  • Hyperbolic cosine: use 'cosh' with 1 operand (an angle) to find the ratio between the adjacent side and hypotenuse of its hyperbola.
  • Hyperbolic tangent: use 'tanh' with 1 operand (an angle) to find the ratio between the opposite and adjacent sides of its hyperbola.
  • Inverse hyperbolic sine: use 'arsinh' with 1 operand to find the angle it makes with the opposite side and hypotenuse of its hyperbola.
  • Inverse hyperbolic cosine: use 'arcosh' with 1 operand at least 1 to find the angle it makes with the adjacent side and hypotenuse of its hyperbola.
  • Inverse hyperbolic tangent: use 'artanh' with 1 operand between -1 and 1 inclusive to find the angle it makes with the opposite and adjacent sides of its hyperbola.

Constants

  • pi: use 'pi' to get the ratio between a circle's circumference and its diameter. Value = 3.1415...
  • tau: use 'tau' to get 2 lots of pi - the number of radians in 360 degrees. Value = 6.2831...
  • e: use 'e' to get Euler's number. Value = 2.7182...
  • g: use 'g' to get the acceleration due to gravity close to the Earth's surface. Value = 9.80665
  • phi: use 'phi' to get the golden ratio found in many places in nature. Value = 1.6180...

calculator's People

Contributors

jamesw1892 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.