These include +, -, *, / like we saw in the previous section. In Python, there are many operations built into the language when the REPL starts. To use Python's trig functions, we need to introduce a new concept: importing modules. Trigonometry functions such as sine, cosine, and tangent can also be calculated using the Python REPL. (The underscore _ in Python is comparable to the ans variable in MATLAB) > 2 * 5Ī summary of the arithmetic operations in Python is below: Operator We can use Python to find the mass of the batteries and then use the answer, which Python saves as an underscore _ to use in our next operation. What is the volume of the battery if each the length, width, and height of the battery are all 3 cm? > 3 ** 3įind the mass of the two batteries and two cables. To complete this problem, use the double asterisk symbol ** to raise a number to a power. What is the area of the base of the battery? The length, width, and height of each battery is 3 cm. What is the total mass if we have 2 batteries, and each battery weighs 5 kg? > 5 * 2 If the battery has a mass of 5000 g and a volume of 2500 cm^3 What is the density of the battery? The formula for density is below, where D is density, m is mass and v is volume. What is the mass of the leftover assembly? > 8 - 1.5 Suppose one of the cables above is removed and it has a mass of 1.5 kg. What is the mass of the battery cable assembly? > 5 + 3 Suppose the mass of a battery is 5 kg and the mass of the battery cables is 3 kg. Try the following commands at the Python REPL: This process repeats over and over again in a continuous loop. After the output is printed, the > prompt appears on a new line. Programmers type commands at the > prompt then hit to see the results.Ĭommands typed into the Python REPL are read by the interpreter, results of running the commands are evaluated, then printed to the command window. The Python REPL shows three arrow symbols > followed by a blinking cursor. REPL stands for Read Evaluate Print Loop. Simple arithmetic calculations can be completed at the Python Prompt, also called the Python REPL. Python can be used as a calculator to make simple arithmetic calculations. Python can also be used for trigonometric calculations and statistical calculations. Python can be used as a calculator to compute arithmetic operations like addition, subtraction, multiplication and division. Python as a Calculator Python as a Calculator Problem Solving with Python Book Construction