Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Shows computations with numbers [Mu: Python 3]
- # Copyright 2022, 2023 Roland Richter
- print("=== Arithmetic operators ===")
- print("Addition: 42 + 3.14 is", 42 + 3.14)
- print("Subtraction: 42 - 3.14 is", 42 - 3.14)
- print("Multiplication: 42 * 3.14 is", 42 * 3.14)
- print("Division: 17 / 5 is", 17 / 5)
- print("Floor division: 17 // 5 is", 17 // 5)
- print("Modulus operator: 17 % 5 is", 17 % 5)
- print("=== Assignment operators ===")
- x = 42
- print("do 'x = 42', and x is", x)
- x += 3.14
- print("do 'x += 3.14', and x is now", x)
- y = 42
- print("do 'y = 42', and y is", y)
- y -= 3.14
- print("do 'y -= 3.14', and y is now", y)
- z = 42
- print("do 'z = 42', and z is", z)
- z *= 3.14
- print("do 'z *= 3.14', and z is now", z)
- print("=== Comparison operators ===")
- if x == y:
- print("x is equal to y:", x, "==", y)
- if x != y:
- print("x is not equal to y:", x, "!=", y)
- if x < y:
- print("x is less than y:", x, "<", y)
- if x > y:
- print("x is greater than y:", x, ">", y)
- if y <= z:
- print("y is less than or equal to z:", y, "<=", z)
- if y >= z:
- print("y is greater than or equal to z:", y, ">=", z)
- print("=== Integer numbers ===")
- print("the answer is:", 42)
- print("the number 42, in binary notation:", bin(42)) # starts with prefix 0b
- print("the number 42, in hexadecimal notation:", hex(42)) # starts with prefix 0x
- print(
- "largest 8-bit unsigned integer:",
- bin(0b11111111),
- "=",
- 0b11111111,
- "=",
- hex(0b11111111),
- )
- # ----------------------------------------------------------------------
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <https://www.gnu.org/licenses/>.
Advertisement
Add Comment
Please, Sign In to add comment