Module 5 Unit 2 - Intro to Python Programming

Callysto.ca Banner

Module 5 Unit 2 - Intro to Python Programming#

Unit Learning Objectives#

By the end of this unit, you will be able to

  • Use variables in Python

  • Perform mathematical operations in Python

  • Simplify programming through the use of loops

  • Create conditions using if/else statements in Python

Basics of Programming#

In order to learn about programming in a Jupyter Notebook, we think it best for you to do all of this directly in a Jupyter notebook. In this notebook, you will learn about the following basics of programming:

Variables

Variables are one way to name data. Programs then use that information again throughout the program. Unlike other programming languages, Python has no command for declaring a variable. The first time you enter a variable, python recognizes it as such. A variable is created the moment you first assign a value to it.

Mathematical Operations

In Module 3, we learned about LaTeX, which allowed you to format a math equation, but did not calculate or compute the math equation. LaTeX only helped with displaying the equation. In Code cells, python can be programmed to compute mathematical operations.

Loops

A loop in programming is a set of instructions that you can make repeat until a certain requirement is met. Recall how loops were used in Module 2 in the knitting example to simplify the instructions.

If/else Statements

These are conditional statements used in programming. IF is used when you want to write a statement or step to evaluate if a condition has been met. ELSE is used to indicate what happens when the condition is not met.

Recall how IF/ELSE statements were addressed in Module 2

When following directions:

  • IF you are facing south:

    • turn around until you face north and then start walking

  • ELSE

    • Start walking

External Activity: Python Exercises#

Work through this Jupyter Notebook for an Introduction to Python programming. Take Python for a test drive as we go through some of the basics. Remember to “Run” your cells.

Want to check your work? Open this Python notebook and compare to the one you were working on.

Callysto.ca License