Introduction to Python
Welcome to the basic programming course. In this section you learn the basics of programming in Python 3:
- How to write your first program
- Variables and data types
- Selection (if statements)
- Iteration (loops)
We will work on two tasks: a maze game and a quiz.
Starting the Python shell
Assuming that you have Python installed you will want to get started! The video below demonstrates how to start to writing simple statements in Python. We are using Python 3 and using the Idle editor. In this first video we will show you how to send output to the screen using the keyword print and how to input data from the user using the keyword input. We also introduce the concept of a variable.
Saving your programs
In the last section, we used the Python shell to write statements and get an instant response.
However, we could not save any of the statements we wrote.
To write a simple program we need to open the text editor in Idle by selecting File then New Window. As an example, here is a simple first program which asks a user for their name and then greets them.
The video below shows step-by-step how to create and run this program.
You can also format the output in a more efficient way that will be useful as you make more complex programs. This uses the format function and is shown in the next short video clip.
Using the skills demonstrated above:
- Write a program to input two messages and output them to a user.
- Write a program to input two whole numbers, add them together and print the result to the screen.
Tip: When inputting numbers, use
int(input()) instead of
input() - more on this later.
- Next - Data types and Operators
- 1. Introduction to Python
- 2. Data types and Operators
- 3. String Operation and Math Unit Exercises
- 4. The IF Statement
- 5. More on IF
- 6. The Maze Game
- 7. Selection Exercises
- 8. FOR Loops
- 9. While Loops
- 10. Making a quiz
- 11. Iteration Exercises
- 12. Lists, Functions and Files
- 13. Creating a list
- 14. Lists with a FOR Loop
- 15. List operations
- 16. Consolidation
- 17. Lists Exercises
- 18. Functions
- 19. Parameters
- 20. Functions with parameters
- 21. Menu Program
- 22. Functions Exercises
- 23. Reading from a file
- 24. Reading from a file - Part 2
- 25. Writing to a file
- 26. Extending the Quiz