๐ ๐ ๏ธ Engineering with Python Operators#
โ๏ธ Operators in Action#
Operators are like the tools in your engineering toolbox. Use them to construct logic, calculate results, or string together ideas.
๐ง Arithmetic Operators#
When you need to crunch numbers faster than a Drexel Dragon chases deadlines:
num1 = 15
num2 = 7
print(f'Addition: {num1} + {num2} = {num1 + num2}')
print(f'Subtraction: {num1} - {num2} = {num1 - num2}')
print(f'Multiplication: {num1} * {num2} = {num1 * num2}')
print(f'Division: {num1} / {num2} = {num1 / num2:.2f}')
Addition: 15 + 7 = 22
Subtraction: 15 - 7 = 8
Multiplication: 15 * 7 = 105
Division: 15 / 7 = 2.14
Tip
Up above we used a cool thing called an f-string. Itโs a way to insert variables into strings. Just put an f
in front of the string and use curly braces {}
to insert the variable. We will talk more about this later.
๐งฎ Modulus & Exponentiation#
Modulus is great for figuring out whatโs left over after dividing. Exponents are for showing off your power (literally).
mod_result = num1 % num2
exp_result = num1 ** 2
print(f'Modulus: {num1} % {num2} = {mod_result}')
print(f'Exponentiation: {num1}^2 = {exp_result}')
Modulus: 15 % 7 = 1
Exponentiation: 15^2 = 225
๐ Relational Operators#
Use these to compare things (like whoโs been in the lab longer):
lab_hours_A = 5
lab_hours_B = 10
print(f'Is A working less than B? {lab_hours_A < lab_hours_B}')
print(f'Is A working equally hard as B? {lab_hours_A == lab_hours_B}')
Is A working less than B? True
Is A working equally hard as B? False
๐ค Logical Operators#
When you need to design circuits of logic (or debug them):
is_efficient = True
is_effective = False
print(f'Logical AND: {is_efficient and is_effective}')
print(f'Logical OR: {is_efficient or is_effective}')
Logical AND: False
Logical OR: True
๐งฉ String Operators#
Engineering isnโt all numbers. Sometimes, you need to print banners for your achievements:
banner = 'Drexel ' + 'Engineering'
print(banner)
Drexel Engineering
๐ Conclusion#
Congratulations, engineer! You now wield the power of Python operators. Apply them wisely in your projects, and may your code be as strong as a Drexel Dragon! ๐