1 of 19

CP 101P

Lesson 1

The Basics

2 of 19

Class Schedule

Week 1: Integers

Week 2: If Statements

Week 3: Strings and Lists

Week 4: Loops

Week 5: Functions and Modules

Week 6: Calculator Project

Week 7: Review

Week 8: Final!

3 of 19

What is Python?

  • Python is one of many programming languages that is used to interact with computers

  • Programming languages are used to create programs

4 of 19

First Python Program

In your code editor, write this line of code

>>>

print(“Hello World!”)

This will output, “Hello World!” to the console

5 of 19

Syntax

  • In programming, we have a term called syntax

  • Syntax is the grammar for programming languages

Different languages have different syntax.

  • Ex. Python has differing syntax than Java

6 of 19

Syntax Examples

Python Java

7 of 19

Variables

  • Variables are like jars you can use to store information
  • Each variable will have a unique name, and can be of four main data types
  • These data types are:
    • Integers (Whole number)
    • Strings (Words or Text)
    • Float (Decimal numbers)
    • Lists (lists of data)

8 of 19

Variables

There are rules to what names you can give to variables.

  • Cannot start with number
  • Can only have alphanumeric characters (a-z, 0-9)
  • Variable names are case sensitive (ex. Name and NAME are two different variables.

9 of 19

Variable Syntax

Here is how you define a variable:

>>>

myvar = 9

print(myvar)

This will output the number 9

10 of 19

Data Types

Here are what the different data types look like:

Integer: A whole number

Ex. 1 and 10 are integers

Float: A decimal number

Ex. 1.8 and 9.0 are floats

String: Words or Text

Ex. “Hello” and “9” are strings

Note: Strings MUST have quotation marks

List: A list of numerous data types

Ex. [1, “hi”, 3, 9.0]

Java Note: Data types do not have to be explicitly declared in Python

11 of 19

Arithmetic Operators

In Python, we have symbols for different math operations

12 of 19

Booleans

  • This is another data type in Python
  • Unlike other data types, Booleans can only equal:
    • True
    • False
  • They can come as a result of comparison operators
    • Ex. print(5 > 9) will output, False
    • Ex. print(2 < 5) will output True

13 of 19

Comparison Operators

Here are comparison operators in Python. They will always result in a boolean

14 of 19

Arithmetic Operators

Here are shortcuts you can use for performing operations on variables

15 of 19

Arithmetic Operators

Let’s use arithmetic operators with variables

>>>

myvar = 8 + 7

print(myvar)

This will output the number 15

16 of 19

Arithmetic Operators

You can add variables as well

>>>

myvar1 = 12

myvar2 = 4

print(myvar1 + myvar2)

This will output 16

17 of 19

Your Turn!

Solve this problem:

Create 3 variables containing integers, with any name that you pick. Then multiply the 3 of them together and print.

Hint: * is the symbol for multiplication

18 of 19

Your Turn!

Solve this problem:

Create 2 Variables and compare the two using the == comparison operator. Save this to a variable and print your variable

3 variables total

2 are going to be integers

1 variable will be equal to the comparison of the two variables

19 of 19

Questions?

Email:

codingpower101@gmail.com

Website: codingpower.org

Discord: https://discord.gg/TDFMVxdVqQ

Help Session: 3:30 to 4:30 PM Sundays!

Contact us here: