Lesson 2

Main Concept: Building blocks of programming and writing your first programs.

Here are a few things that can help you understand the Main Concept for todays lesson:

1. Input, Process, Output
2. Outputting info from the computer (Printing)
3. Inputting info into a computer (Input) 4. Saving info for later (Variables)
5. Different types of data (Data Types) 6. Combining variables and using formulas (Expressions)
7. Add, Subtract, Multiply, Divide, Floor Division, Modulo (Operators)
8. Please Excuse My Dear Aunt Sally (Order of Operations)
9. English vs. Python (Syntax)

By the end you will be able to: Understand what it means to code and know what’s necessary to get started.

Here's a 2 page PDF that covers the same content if that's easier for you

1. Input, Process, Output

When asked a question, you usually, hear it, think about it, and respond. Computers are the same way, when you write a program, it often contains inputting information, processing, and outputting it.

2. Printing (Outputting Info)

Outputting information from a computer. Just like you can ask a person, “what is 5×5” and they respond by saying “25” you can ask a computer to output the answer of 5×5. You do this by asking the computer to: print.

 

print(‘Hello World’) —-> Hello World

3. Inputting (Inputting Info)

Inputting information into your computer. Just like you can ask a person, “what is your birthday”, they say, “December 20, 1995”. They inputted the numbers into your brain and you try remember it so you can say happy birthday to them on that day. We can do this with a computer too, and we can save the answer to the question we asked into what we call a variables which we’ll explain below:

 

Birthday = input(“what is your birthday”)

Let’s pretend they inputted —> “December 20, 1995”

print(Birthday) gives us —–> “December 20, 1995”

4. Variables (Saving Things For Later)

If you look above at the word Birthday, we would call that a variable. The reason why is because it is a storage unit in Python. We use it to store data, the data in this storage can change or be variable, hence the name “variable”. Variables can contain numbers, letters, big numbers, small numbers. A bunch of stuff. Some examples of declaring variables are:

 

Number = 5
Name = “Jeff”
Birthday = “12/20/1995”

5. Data Types (Numbers and Letters)

Notice that the variables above are all a bit different. Some contain just numbers, some contain just letters, and some contain a mix of both. We consider a variable that has letters in it, a string. Strings can be single words, or sentences, they can even have numbers in them. Strings are always wrapped in quotes, either single ‘ or double “. A variable that has only numbers in it, we call either an int, or a float.

6. Expressions (x = y + 5)

We can think of an expression as an equation in elementary math. If we say, x = 5 + 7. We now know that x = 12. Now in coding terms, if x is a variable, and it has the value of 12. If we then say y = x + 5. The value of x is added to 5 (12 + 5) and the result is 17. Now, y = 17.

7. Operators (+-*/%)

Just like we used addition in the explanation above, we can also use subtraction, multiplication, division, and even some extra operators called floor division and modulo.

 

 

Floor division allows you to divide to numbers, and get out only an integer quotient, with no remainder. Meaning if you divide 11/2, normally we would get 10.5 or 10 remainder 1, but with floor division 11 // 2 = 10. We essentially remove anything after the decimal place, we don’t round up or down. Also note, we use // to denote floor division.

 

Modulo allows you to divide to numbers, and get out only the remainder as a result. Meaning if you divide 11/2, normally we would get 10.5 or 10 remainder 1, but using modulo, 11 % 2 = 1. We essentially are only getting the remainder out of a division, nothing else.

8. Order of Operations (PEMDAS)

Just like we learned in elementary education, “Please excuse my dear aunt sally!”. What I mean is, never forget PEMDAS, the order of operations. Expressions will operate in an orderly fashion, following parentheses, exponents, multiplication, division, addition, subtraction.

 

X = (5+7) * 5 —-> X = 60

9. English vs. Python (Syntax)

In English, we have certain ways we write so people understand us, we call it our languages syntax. We use capital letters at the beginning of sentences, periods at the end of sentences, and plenty of grammar to help. Python and other languages are the same way, but have different rules. They use parentheses, equal signs, and a variety of other symbols. You have to write according to Python’s syntax otherwise the computer won’t understand you.

10. Next steps!

Start playing around with printing, inputting, and saving info into variables. A starter project could be making a calculator that when given 2 numbers, adds, subtracts, multiplies, and divides them, and then prints out the results. You could also make a quadratic formula solver. After you play around, go to spartantutorsmsu.com/learn to go to our next lesson!

Next Lessons Content

Main Concept: Making decisions with code.

By the end you will be able to: Know how to make decisions in your code and do different things depending on what the user inputs.

Last Lessons Content

Main Concept: Understand what coding is, why it is important, and how to get started.

By the end you will be able to: Understand what it means to code and know what’s necessary to get started.

Last Lessons Content

Next Lessons Content

Main Concept: Understand what coding is, why it is important, and how to start.

By the end you will be able to: Understand what it means to code and know what’s necessary to get started.

Main Concept: Making decisions with code.

By the end you will be able to: Know how to make decisions in your code and do different things depending on what the user inputs.

If you'd like to have a qualified tutor explain this lessons content to you, download our Spartan Tutors app today!