Introduction
Welcome!
This lesson introduces the most essential beginner topics of Python programming.
Press the 'Next' button to proceed with the lesson.
Running code
On the right are two boxes. One is for writing code in. The other shows the result of running your code.
Press the 'Run Code' button and see what happens.
After running the code, you should see a number appear in the 'Output' box.
Then press 'Next' to continue to the next slide.
Using print
The code you ran used print
to show the number 123
in the output box.
Generally, print
is one of the most-used commands in programming. It shows
information on your screen. Without print
, your program would show nothing
when run.
Your first challenge is to change the code so it shows the number 2
in the
output box when you run it.
Therefore, change the code in the code box from print(123)
to print(2)
.
Then press 'Submit Answer' to check your solution before continuing.
Larger programs
Python programs can have more than one line. Some programs have hundreds of lines of code.
Here is an example of a program with two lines of code:
print(123)
print(456)
Python will run the lines one at a time, starting at the top. When a print
is reached, the value between the parentheses is shown in the output box.
Try to run the code and see what it does.
Then change the code so that it prints 10
on the first line, and 100
on the next line. Submit your answer before continuing.
Using print from scratch
Now that you have seen some examples of using print
, try writing a line of
code from scratch. Your code should use print
to show the number 42
in the
output box.
You can refer back to previous slides if you don't remember exactly how to use
print
.
Note that upper- and lowercase letters, spelling, and parentheses must all be correct when writing code -- otherwise Python won't understand you. Make sure you follow the previous examples closely.
Basic addition
If you put a math expression into print
then Python will calculate it for
you before printing it.
Here is an example of code that calculates and prints 2+3
:
print(2+3)
Use this as a basis for your own addition program.
To continue, write code that calculates 123 + 456
and prints the result.
Multiplying and subtracting
Next, use print
twice. First calculate 42 * 56
. Then calculate 88 - 512
.
If you are not sure how to proceed, try pressing the Hint button.
More maths
Use a single print
to do a calculation that uses both plus, times, and
minus in one line.
If you need a hint, you can press the 'Hint' button.
Conclusion
Congratulations on completing the first lesson! You are now familiar with
using print
and working with numbers in Python.
The rest of the course covers all the fundamental concepts you'll need to become competent at programming.
The next lessons introduce strings - a way to represent text - and variables, which let you store values for later use.