Skip to content

Instantly share code, notes, and snippets.

@Anselmoo
Created February 9, 2023 16:39
Show Gist options
  • Save Anselmoo/f4763afb588cf0fda96255cba099c876 to your computer and use it in GitHub Desktop.
Save Anselmoo/f4763afb588cf0fda96255cba099c876 to your computer and use it in GitHub Desktop.
Cross check of /= and += operators
def case_1() -> None:
"""Case 1: regular integer incrementation"""
for _ in range(10):
i = i + 1
print(i)
def case_2() -> None:
"""Case 2: integer incrementation with division"""
i: float = 1.0
for _ in range(10):
i = i / 2
print(i)
def case_3() -> None:
"""Case 3: integer incrementation with division and while loop"""
i: float = 1.0
while i > 0.1:
i = i / 2
print(i)
def cross_check() -> None:
"""Cross check with /= operator"""
i: float = 1.0
j: float = 1.0
for _ in range(10):
i = i / 2
j /= 2
print(i == j)
if __name__ == "__main__":
case_1()
case_2()
case_3()
cross_check()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment