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 (
a
andb
) together. - Subtraction: Subtracts
b
froma
. - Multiplication: Multiplies the numbers (
a
andb
). - Division: Divides
a
byb
and gives the result as a float. - Floor Division: Divides
a
byb
and returns the integer part of the result (ignores the decimal part). - Modulo: Returns the remainder when
a
is divided byb
. - Power: Raises
a
to the power ofb
(exponentiation).
- Equal to (
==
): Checks ifa
is equal tob
. - Not equal to (
!=
): Checks ifa
is not equal tob
. - Greater than (
>
): Checks ifa
is greater thanb
. - Less than (
<
): Checks ifa
is less thanb
. - Greater than or equal to (
>=
): Checks ifa
is greater than or equal tob
. - Less than or equal to (
<=
): Checks ifa
is less than or equal tob
.
- Assign values to the variables
a
andb
. - 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)