Week 6
Variables, Expressions, and Statements
Weekly Summary
For the remainder of the semester we will be programming in the text-based, Python programming language.
This week we will look at the building block operators in Python that allow us to perform basic mathematical operations and store results in appropriate variables.
Recall from our prior Scratch Unit that we defined variables as:
Learning Outcomes
By the end of the week students should be able to:
- Given the name for a variable, indicate whether it is a legal name in python (does it follow the rules of syntax).
- Given one or more mathematical expressions using the python mathematical operators, indicate the result.
- Describe the function of the three Python division operators.
- Explain differences between integer and floating-point data.
- Given one or more statements that set the value of a variable, indicate the data type of the variable.
- Given one or more statements, indicate the value(s) in one or more variables upon completion of the statements.
- Given a print statement, determine the output.
Learning Materials
If you didn't attend the CoP on Saturday...
PRIOR to starting this week's materials you should make sure that you have done some activities that were completed at the Community of Practice event on Saturday, September 23. These include:
- Install some software and create some accounts
- Complete an activity that has you reading Python code
- Complete an activity that has you focus on some structure of Python
Getting Started with Python
- LESSON - Python is an interpreted language
- LESSON - Using several Python IDEs
Paired or Small-group Activity
If we were working in a face-to-face classroom I would have you complete the following POGIL activity in groups of 3 or 4 [which is the intention of POGIL activities]. Since we are not face-to-face I give you the option of either:
- completing this on your own
- completing this face-to-face with a small group of peers
- completing this online with a small group of peers
The choice is yours and you don't have to tell me (because I'm not collecting this activity. It's for learning purposes, not grading purposes).
Textbook Readings
- Log on to your online textbook
- Read the following sections from your textbook
- 2.1 Values and Types
- 2.2. Variables
- 2.3. Variable names and keywords
- 2.4. Statements
- 2.5. Operators and operands
- 2.6. Expressions
- 2.7. Order of operations
- 2.8. Modulus operator
- 2.9. String operations
- 2.10. Asking the user for input
- 2.11. Comments
- 2.12. Choosing mnemonic variable names
- 2.13. Debugging
Additional Explanations
Think of the following a little bit like podcasts. I will add videos here as I get questions from students or when I decide that I need to say something more beyond what is in the book. These won't "drop" on a particular day like the podcasts did in FCCS, but will get added as the need arises. I would suggest you watch this space to see if new stuff has shown up. And if you have questions and feel there is a video that needs to go here PLEASE email me and let me know.
- VIDEO: A few thoughts about Chapter 2.
- VIDEO: Our four primitive data types [int, float, str, bool] (Fairly important to understand)
- VIDEO: Two types of quotation marks? (Moderately important to understant)
- VIDEO: What the flip is PEP 8 and what do we care? (Clarification)
- LINK: Official PEP 8 Document
- LINK: Summary of PEP 8 Document
- VIDEO: The "suite" of division operators [ /, //, % ] (This is VERY important to understand)
- VIDEO: The shortcut assignment operators [ +=, -=, *=, /= ] (Not something I will use in this course but something the book showed you).
- VIDEO: A little bit about Python special/escape characters [ \n, \t, \\ ] (Not something we will use until much later in the course, but something the book showed you).
- VIDEO: Explaining Assignment Statements (using Activity 2.4.2 from Runestone)
Additional Practice
The following problems are entirely optional but are provided here to give you some additional practice if you are interested. They are similar to what would be on a competency demo.
- 2.15. Multiple Choice Questions
- The Multiple-Choice questions are probably the most like the kind of questions you will see on the next competency demo.
- 2.16. Mixed-up Code Questions
- You can attempt these problems in two different ways - as "Parsons Problems" or as "Active Code". You may choose (and I think there is long term benefit in doing it both ways doing Parsons first and then Active Code later).
- Here is a quick video showing you how to use both modes.
Graded Practice
Because we are just getting started with this unit I don't have any programs for you to write yet. Instead, you are STRONGLY encouraged to get started on the next week as soon as possible.
- 2.15. Multiple Choice Questions