CP 101P
Lesson 1
The Basics
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!
What is Python?
First Python Program
In your code editor, write this line of code
>>>
print(“Hello World!”)
This will output, “Hello World!” to the console
Syntax
Different languages have different syntax.
Syntax Examples
Python Java
Variables
Variables
There are rules to what names you can give to variables.
Variable Syntax
Here is how you define a variable:
>>>
myvar = 9
print(myvar)
This will output the number 9
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
Arithmetic Operators
In Python, we have symbols for different math operations
Booleans
Comparison Operators
Here are comparison operators in Python. They will always result in a boolean
Arithmetic Operators
Here are shortcuts you can use for performing operations on variables
Arithmetic Operators
Let’s use arithmetic operators with variables
>>>
myvar = 8 + 7
print(myvar)
This will output the number 15
Arithmetic Operators
You can add variables as well
>>>
myvar1 = 12
myvar2 = 4
print(myvar1 + myvar2)
This will output 16
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
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
Questions?
Email:
Website: codingpower.org
Discord: https://discord.gg/TDFMVxdVqQ
Help Session: 3:30 to 4:30 PM Sundays!
Contact us here: