Welcome to the Python Arithmetic & Comparison Operations script! This fun and simple Python program showcases a variety of basic arithmetic and comparison operations between two numbers, a and b. Whether you're a beginner or an experienced programmer, this code is a great way to understand how different operators work in Python. Let's dive into the world of numbers and operations! ✨
The script performs the following operations:
- Addition: Adds the two numbers (
aandb) together. - Subtraction: Subtracts
bfroma. - Multiplication: Multiplies the numbers (
aandb). - Division: Divides
abyband gives the result as a float. - Floor Division: Divides
abyband returns the integer part of the result (ignores the decimal part). - Modulo: Returns the remainder when
ais divided byb. - Power: Raises
ato the power ofb(exponentiation).
- Equal to (
==): Checks ifais equal tob. - Not equal to (
!=): Checks ifais not equal tob. - Greater than (
>): Checks ifais greater thanb. - Less than (
<): Checks ifais less thanb. - Greater than or equal to (
>=): Checks ifais greater than or equal tob. - Less than or equal to (
<=): Checks ifais less than or equal tob.
- Assign values to the variables
aandb. - Run the script to get the output of the operations.
- See the results of each operation printed to the console. ✨
# Define numbers
a = 7
b = 2
# Addition
print('Sum: ', a + b)
# Subtraction
print('Subtraction: ', a - b)
# Multiplication
print('Multiplication: ', a * b)
# Division
print('Division: ', a / b)
# Floor Division
print('Floor Division: ', a // b)
# Modulo
print('Modulo: ', a % b)
# Power
print('Power: ', a ** b)
# Comparison Operators
print('a == b =', a == b)
print('a != b =', a != b)
print('a > b =', a > b)
print('a < b =', a < b)
print('a >= b =', a >= b)
print('a <= b =', a <= b)