# What is x y in Python 6

## Calculating with python3

As the next step, we will test the calculator suitability of the python interpreter. Call the Python interpreter, if it is not already open, and off you go.

user @ linux: ~> python3 Python 3.2 (r32: 88445, Feb 21 2011, 04:07:45) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 1 + 2 + 3 6 >>> 1 * 2 * 3 6 >>> print (1 + 1) 2 >>> 1+ 1 2 >>> 1 + 1 2 >>> 1 +1 2> >> 3 * 5 15 >>> 3 * 5 -2 13 >>> 3 * (5 -2) 9 >>> So the thing can really do arithmetic. We saw that the 1 + 1 and 1 + 1 work - python is tolerant of spaces in the expression (especially at the beginning of the expression there must be no space).

I prefer 1 + 1 for the sake of clarity.

The calculation rules are of course also mastered. Point calculation before line calculation, and brackets come before everyone else.

In addition to the basic calculation types, there is also the calculation of residual classes and exponentiation. "2 ** 4" is therefore "two to the power of four"

But be careful!

>>> -2**4 -16 >>>I beg your pardon? -2 * -2 * -2 * -2 is 16, and NOT -16. That is also true. But here (in python) it behaves differently in that -1 * (2 ** 4) is executed. So you need the following notation:

>>> (-2)**4 16 >>> You can get an invoice (**in the interpreter, NOT in the script file**) can also be divided into several stages. The fact that the results of a separate calculation are stored in (underscore) helps us to do this. An example is worth a thousand words:

Now let's look at the quirks of dividing.

>>> 2 / 3 0.6666666666666666 >>> 2 // 3 0 >>> 2 // 3. 0.0 >>> A whole number divided by another whole number results in a floating point number (float). If both (divisor and divident) are floats or just one of the two, a float also results.

results in 1.0.

The division is carried out with two slashes in such a way that the result*floored* is, that is, the floating point number is rounded down and output as.

Incidentally, a decimal point is written with and not with (as usual from school)!

>>> 2.4 / 1.2 2.0 >>> Floating point numbers are also mentioned. In English, from which the term **float** has revealed.

We see that both spellings work. Just adding the dot turns int into a float, and what I remember was the same with calculators in the 1970s.

The arithmetic symbols are referred to as.

>>> 14% 4 2 >>> (21 + 9)% 24 # 9 p.m. plus 9 hours 6 >>> 6.8 / 2.4 2.8333333333333335 >>> 6.8 // 2.4 2.0 >>>We have already shown exponentiation above.

>>> 2 ** 3 8 >>> 2 ** 3. 8.0 >>>If you can potentiate, what about pulling roots? Is the?

>>> 4 ** 0.5 2.0 >>> 27 ** 1./3. 9.0 >>>Oups! Ah, the rules of precedence apply again!

>>> (27 ** 1.)/3. 9.0 >>> 27 ** (1./3.) 3.0 >>> (2**0.5)*(2**0.5) 2.0000000000000004 >>> 2**0.5*2**0.5 2.0000000000000004 >>> Calculating with floating point numbers on the computer is associated with (rounding) errors in the microprocessor (CPU), which leads to small inaccuracies that can have a major impact in space travel.

In astronomy you have to take this into account. This is precisely where you need reliable arbitrary precision, and this is obtained by using the decimal module (part of the STL).

For conventional calculations, however, the accuracy of float calculations should be sufficiently accurate.

Another way of pulling roots, which is more common in python, we will soon work on in another link (when we get to know the module).

### Fractions

Calculating with fractions is very simple. We want to get away from **fractions**-Module for the time being only the class **Fraction** to fetch. (If the terms *module* or *class* are still unknown to you, then just accept the lines of code and everything will be clarified later in the *Base*Range on)

So you can do a lot of math. You can also try out subtractions and multiplications of two fractions yourself.

With the built-in function **divmod**() you can see how often the divisor fits into the divident (first value of the return), and how much remainder remains (second value of the return).

Here it goes to the top of the page and there it goes to the python overview

- Entrepreneur, what was your first business ever
- Why do pseudorandom number generators have to be fast
- Can or will reunite Malaysia and Singapore
- When do I leave social media
- Why is time relative 2
- How did the metric system evolve?
- What advantages did child labor bring?
- What is outsourcing used for?
- How mega-churches collect tithe
- Which country has China colonized
- How popular is Aamir Khan in China
- Anorexic stomachs always growl
- Is there a narcissism epidemic in America?
- How is the Czech r pronounced?
- How does a web server work
- Which card games are least associated with luck?
- How does freelance work for a programmer
- Why am I bad at mental math
- Becomes Australia Chaustralia by 2070
- Is Xi Jinping China's Hitler
- Any 1 Website Builder Apps
- Are taxis safe in Bangkok?
- How could I regulate random forest classifiers
- Why did China become a world factory