Python: Math, Less Familiar

  1. Introduction to Python
  2. Python: Choosing a Text Editor or IDE
  3. Python: Hello World
  4. Python: Variables, Strings and Numbers
  5. Python: Variable Naming
  6. Python: Math, Familiar
  7. Python: Math, Less Familiar
  8. Python: Mathematical Order of Operations
  9. Python: Introducing PEP 8
  10. Python: Text Concatenation
  11. Python: if Statements and Comparison Operators
  12. Python: else and elif statements
  13. Python: Testing Multiple Conditions
  14. Python: Testing Sets of Conditions
  15. Python: Nested if Statements
  16. Python: Lists
  17. Python: Adding To and Changing Lists
  18. Python: Lists: Take a Slice, Delete Elements, Popping Elements
  19. Python: Tuples
  20. Python: for Loops
  21. Python: Nested for Loops
  22. Python: Capturing and Formatting User Input
  23. Python: Dictionaries
  24. Python: Functions
  25. Python: While Loops
  26. Python: Creating and Using Classes
  27. Python: Data Files
  28. Python: Modules
  29. Python: CSV Files
  30. Python: JSON Files
  31. Python: Errors and Exception Handling
  32. Python: Using Pexpect
  33. Python : Using Pexpect : ftpTestOffload.sh
  34. Python : Using Pexpect: ftpTest.py
  35. Python: DCL Conversion to Python

Go to Chapter 6 of A Smarter Way.

A. Sometimes you need to find the remainder of a division operation. Really. It sounds crazy, but you’ll see why you’d want this later.

That remainder is called the modulus. And the operator that you use to get it is the modulo operator.

my_modulus = 10 % 3

B. The exponent operator is how you calculate powers of a number.

my_number = 10 ** 3

C. Shorthand operators are quick ways to perform common math.

You could, for instance, do this:

my_number = my_number + 1

But you can do it more simply:

my_number += 1

Both of these operations will add 1 to my_number. And you can do subtraction this way, too.

my_number -= 1

Exercise

Go to http://www.asmarterwaytolearn.com/python/6.html and review the exercises.

  1. Return to your examples.py script.
  2. Create a variable that contains the statement “First Edition: “.
  3. Use a shorthand operator to add 1 to the variable my_year.
  4. Print these two variables on one line.