Chapter 4
Mathematical expressions: Familiar operators
You've just utilized Python to make some basic figuring,
similar to 2 + 2.
The programming term for a count is math articulation. Natural administrators in numerical articulations are + (add), - (deduct), * (duplicate), and/(partition). As you've seen, rather than doling out a number to a variable…
Popular number = 4
…you can allocate the consequence of a mathematical articulation to the variable…
Popular number = 2 + 2
Python makes the
estimation 2 + 2 and relegates the outcome to the variable. In the explanation
above, the popular number is doled out the
amount of 2 + 2—the number 4.
You can compose:
Print (2 + 2)
This Presentations 4
on the screen.
Here's an explanation that deducts 24 from 12, allocating the outcome, - 12, to the variable.
misfortune = 12 - 24
This one appoints the result multiple times 12—outcome 36—to the variable.
handfuls = 3 * 12
This one appoints 12 separated by 4—the outcome is 3—to the variable.
Popular number = 12/4
In the next one, the glide .075 is assigned to the mutable num. Then the digit 200 is added to the adaptable, and the sum, 200.075, is assigned to a second adaptable, total. As usual, you can mix variables and numbers.
1 num = .075
2 totals = num + 200
You can also do a
control using an appearance covering nothing but variables.
1 num
= 10
2 another
num = 1.5
3 sums of numbers = num + another num
In the statement above, the variable sum of numbers winds up with a value of 11.5.
No comments:
Post a Comment