Getting Started (10 min)
- Journal: What environments have you already used to write Python programs?
- Share answers in class.
- After students have shared their answers, introduce the topic of Integrated Development Environments (IDEs). Explain that an IDE provides a way to manage files, write code, get help with code syntax and usage, and the ability to test, run, and debug programs in an environment they are able to configure to their own liking.
- As defined by Wikipedia: “An integrated development environment (IDE) or interactive development environment is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of a source code editor, automation tools, and a debugger. Most modern IDEs offer intelligent code completion features.” (From: http://en.wikipedia.org/wiki/Integrated_development_environment)
- Have students go to Python Central at http://www.pythoncentral.io/the-best-python-ides-you-can-use-for-development/ for a list of the top IDEs for Python. PyCharm is listed as one of the best. Explain to students that they will be learning to use the PyCharm IDE.
- Share tweets from the homework about the 7 aspects of programming quickly standing up in place and sharing.
-
- Catch a shooting star (variables)
- Dictionary (data types)
- Russian Dolls (things within things, instances)
- Sausage (processes)
- The dog, the cat, and the fish (causation, event change)
- Pizza (abstraction) include why abstraction is "like making pizza," and what other kinds of activities might fall into that category.
If they did not assign the homework, review Seven things you should know if you’re starting out programming
Have students go to the article Seven things you should know if you’re starting out programming at
http://www.theguardian.com/info/developer-blog/2011/oct/07/programming-developer-journalist
Activity (20 min)
Introduction to PyCharm
- Find and launch PyCharm. If there is not a shortcut on your desktop, go to Programs >> JetBrains >> JetBrains PyCharm Community Edition 3.4.1.
- The first screen will provide options for Create New Project, Open Directory, Check out from Version Control, Configure, and Docs and How-Tos.
- Select Configure >> Settings >> Appearance. Explore Screens under UI Options. IntelliJ is the default appearance
- Darcula and Windows are some other options.
- Students should explore other options available.
- Students should play with the appearance and select a new one (with your approval) if they have a preference.
- Click the arrow to go back to the Quick Start menu.
- Click Create New Project.
- Give the project a name.
- Click the ellipses (the … at the end of the location field) to navigate to the location you need to save your work.
Teacher note: This may be a good time to have students configure the default Working Directory as shown in the Python and PyCharm Installation and Configuration Guide file in the lesson resources folder.
- When you click “OK,” your project will be created.
- Click File >> New >> Python File to create your .py file. Name your first .py file rate_time.
- The code for this module will be copied from the ‘Non-Programmer's Tutorial for Python 3/Who Goes There?’ tutorial shortly.
- Click OK to create the file.
- The user name of the author of the file will appear at the top of the code window with the default comment method.
- Take students through some configuration modifications, such as adding line numbers, showing the console, and changing the default for comment style, all covered in the Installation and Configuration Guide.
- If you are projecting your screen, you can use Presentation Mode to make viewing easier for students.
- Allow students some time to explore the environment.
- Visit Non-Programmer's Tutorial for Python 3/Who Goes There?
- Prior to copying the code for rate_time.py and area.py, take students through the sections in the Non-Programmer's Tutorial for Python 3/Who Goes There? on Input and Variables.
- Explain and model variable types and their behaviors, and concatenation.
- For ease of use, consider using the comma at this time to avoid confusion about concatenation.
- Create, save, run and debug programs rate_time.py and area.py.
- To run a program for the first time, go to Run and select the file you want to run.
- After that, the Run command will appear in the upper right corner of the PyCharm IDE.
- As you add new modules to the project you will need to go to Run and select the new file.
- After that, the file names will appear in a drop-down menu next to the green Run arrow.
- If it has not already been configured, go to Tools >> Run Python Console to show the console at the bottom of the PyCharm environment. Students can use this to test their code as they have in other environments.
- In the PyCharm console, test code from An Informal Introduction to Python 3.1 Using Python as a Calculator. (https://docs.python.org/3.4/tutorial/introduction.html#using-python-as-a-calculator).
Summative Assessment (20 min)
Students are to:
- Create a new Python module (.py) called name.py.
- Comment in their name, date, and name of project as directed by their instructor at the top of their code window.
- Assign their full name to an appropriately named variable.
- Assign their age to an appropriately named variable.
- Output their name and age as a sentence, with variables and literal values concatenated correctly.
- Debug any errors and run their program with the correct output and without error.
Sample code (will throw an error)
# author = 'iam tester'
# date July 4, 2024
# name.py
name = 'Ima Tester'
age = 15
print (name + " is " + age + " years old.")
The above code will throw an error, because age
is an integer and needs to be expressed as a string OR concatenated using a comma (,)
.
name = 'Ima Tester'
age = 15
print (name,"is",age,"years old.")
Important notes about naming your files and variables:
- Our Python coding examples will follow the PEP 8 Style Guide. (http://legacy.python.org/dev/peps/pep-0008/)
- Teachers are not required to use this standard but should establish their classroom conventions for students to follow.
- Modules written in Python, .py file names, should be in all lower case as is done with the sample files in the Python for Everybody textbook. (https://www.py4e.com/code3/)
- Variable names should begin with a lowercase letter with multiple words separated by an underscore.
- Teachers may choose to use camelCase or another naming system and should be specific and consistent with students regarding these requirements.
- Python file names and variable names must not begin with a number, and cannot be the same as Python keywords:
and del from not while
as elif global or with
assert else if pass yield
break except import print
class exec in raise
continue finally is return
def for lambda try
(from http://www.pythonforbeginners.com/basics/keywords-in-python)
- For more information concerning variable names and keywords to Python, go to
Homework Assignment
- Use two sources to find definitions of "algorithm", cite the sources
- Write down the steps involved in a daily task – creating a peanut butter and jelly sandwich; getting to school; brushing teeth; completing homework; etc…)
Students can work in pairs, side by side, to help each other through each step of the process.