* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Mathematical Operators
List of important publications in mathematics wikipedia , lookup
Mathematics wikipedia , lookup
Bra–ket notation wikipedia , lookup
Location arithmetic wikipedia , lookup
History of mathematical notation wikipedia , lookup
Secondary School Mathematics Curriculum Improvement Study wikipedia , lookup
Mathematical proof wikipedia , lookup
History of trigonometry wikipedia , lookup
Mathematics and architecture wikipedia , lookup
Philosophy of mathematics wikipedia , lookup
History of mathematics wikipedia , lookup
Foundations of mathematics wikipedia , lookup
Mathematics and art wikipedia , lookup
Ethnomathematics wikipedia , lookup
Mathematical anxiety wikipedia , lookup
Oscillator representation wikipedia , lookup
Mathematical Operators You are already familiar with the add, subtract, multiply and divide operators from math class. In programming, the symbols for multiply and divide are a little different. For multiplication use the star symbol * and for divide use the forward slash symbol /. The computer intrepreter follows the same rules for "order of operations". - PEMDAS - Parentheses have the highest precedence and can be used to force an expression to evaluate in the order you want. Since expressions in parentheses are evaluated first, 2 * (3 - 1) is 4, and (1 + 1)**(5 - 2) is 8. You can also use parentheses to make an expression easier to read, as in (60 * 100) / 10, even if it doesn’t change the result. - Exponentiation has the next highest precedence. If you want the computer compute 3 2 , it would be coded as: 3**2 - Multiplication and Division have the same precedence, which is higher than Addition or Subtraction. - Addition and Subtraction also have the same precedence. So 2*3 - 1 is 5, not 4, and 6+4/2 is 8, not 5. - Operators with the same precedence are evaluated from left to right. For example, 100 / (2 * 5) is 10 not 250 * Special Mathematical Functions: - pi, sine, cosine, tangent, are built into the Python math library. These functions may be used in any Python code, but will require linking to the library by inserting from math import* at the top of your script. Try googling (python math library). Concatenation of Strings and Mathematical Operators Python has the capability of performing mathematical operations and concatenating them with a string. Use a comma between the string expression and the mathematical expression. Parentheses are added around the mathematical operation to denote that these two numbers will be added together. Using parentheses is always a good way to eliminate errors. 1/2 Mathematical Operators print "The sum of 4 + 4 is ", (4+4) print "If the DVD costs $10 and I only have $3, I am short",(10-3),"dollars." 2/2