Python: Comments + arithmetic operators 3/12

in #programming6 years ago

Source.

We will start today with class number three that I have decided to share with you, I will not be very descriptive about the presentation of this post, since I do not want to stretch so much, it will be entertaining that I can assure you, without anything else to say we will touch the first topic of today.

The comments.


Source.

It is about including comments, these comments are notes that have no effect at the time of our program, it is as if they were invisible to the program but we can see and we can support them, they serve as indicators, There may be times when you work with other people's codes, and it turns out to be a headache to know which function meets each code, but with the comments we can give a description of what function has a certain block, or what certain variables serve us, basically the comments are certain helps to better understand the language next to the code, so that the line is taken as a comment will be necessary to put the sign of the numeral "#" with a space before the text.

For example:


Source.

Because it is treated as a comment we can see that it changes the color of the letters in a grayish way, this time it does not mark the bright colors of always.

Fact:

Source.

The PEP8:


It indicates that after the sign of the numeral there must be a space and then the comment.

Arithmetic Operators.





Source.

Are those that allow performing arithmetic operations, these operations are:

Sum: +

Subtraction: -

Multiplication: *

Division: /

Integer division: //


In case we want to divide with greater accuracy, and are 2 whole numbers we will only put //.

The module is also available.

Module:%


It allows us to calculate the residual of a division.

Exponent: **


It allows us to handle powers.

Declaring variables assigning arithmetic operations.

For example:

Add = 20 + 3 + 3 + 3 + 1

Subtract = 50-49 + 1

Multiply = 100 * 10

Divide = 27/4

Residue = 27% 4

Exponent = 3 ** 3


Regarding arithmetic operators, the PEP rules refer to the fact that before and after an operator there must be a space.

When printing variables, the Print must be placed.

For example:

Print (Add)

30

We will calculate the surface of a triangle.


Source.

The formula of the procedure would be base * height / 2.

We are going to need a base variable that would be worth 30 together with a height variable that will be 50, so we will need to use an arithmetic operation to carry this out, such as base X height between 2. All this operation is going to be assigned to a variable that will be called surface, that will have assigned the result of the operation.

Only the surface would be printed.

For example:

Base = 30

Height = 50

Surface = Base * Height / 2

Print (Surface)

750.0 = Surface of our triangle.

With this I will finish the objective three of these tutorials, this is a simple and entertaining programming language, it is a matter of putting a little practice.

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 62890.35
ETH 2544.51
USDT 1.00
SBD 2.94