Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new016_operators.py #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions 016_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,42 +54,44 @@ def add_one(num):

# == Subtraction ==

# subtracted = 2 ? 3
# print(f"2 ? 3 = {subtracted} (should be -1)")
subtracted = 2 - 3
print(f"2 - 3 = {subtracted} (should be -1)")

# == Division ==

# divided = 2 ? 3
# print(f"2 ? 3 = {divided} (should be 0.6666666666666666)")
divided = 2 / 3
print(f"2 3 = {divided} (should be 0.6666666666666666)")

# This kind of 'decimal point' number, 0.6666666666666666 is
# called a float, by the way, meaning 'floating point'.

# == Modulus ==
# Sometimes known as "remainder if we divide 3 by 2"

# modulus = 3 ? 2
# print(f"3 ? 2 = {modulus} (should be 1)")
modulus = 3 / 2
print(f"3 / 2 = {modulus} (should be 1)")

# == Floor division ==
# Sometimes known as "division without remainder"

# floor_divided = 2 ? 3
# print(f"2 ? 3 = {floor_divided} (should be 0)")
floor_divided = 2 / 3
print(f"2 / 3 = {floor_divided} (should be 0)")

# == Exponentiation ==
# Sometimes known as "2 to the power of 3"

# expr = 2 ? 3
# print(f"2 ? 3 = {expr} (should be 8)")
expr = 2 ** 3
print(f"2 ** 3 = {expr} (should be 8)")

# There are many more operators in Python that you can
# research. You're very welcome to try out a few below:

# OPERATOR PLAYGROUND STARTS
expr = 6 / 3
print(f"6 / 3 = {expr} (should be 2)")



expr = 6 // 3
print(f"6 // 3 = {expr} (should be 2)")
# OPERATOR PLAYGROUND ENDS

# Happy? Move on to 017_expressions.py