Lesson 1 – Introduction to Python
In this lesson you will:
- See what Python is used for.
- Use
print()to show messages. - Use
input()to ask the user a question. - Read and predict simple Python programs.
By the end you should be able to:
- Say what Python is used for.
- Use
print()andinput()correctly. - Explain what small programs will do.
1. What is Python?
A programming language is a way to write instructions that a computer can understand and follow. Python is one such language. You give Python instructions; the computer carries them out.
Key points:
- Python is high-level: easier for humans to read and write.
- Python runs your code normally line by line from top to bottom (though later you'll learn constructs like loops and conditions that can change this flow).
- Python is used for apps, websites, games, and data analysis.
💾 Export your code: You can export your work as a .py (Python) file to run later in a desktop IDE. Look for the "Export as .py" button in the coding tasks section at the end of this lesson.
Quick example
print("Hello from Python!")
This makes the computer show:
Hello from Python!
Try it yourself
Change the message inside the quotes and run it.
Output
Example Solution
print("Hello from Python!")
print("I can change this message!")
2. Running code + Output with print()
You don't need to create files for this course. The web page already gives you a Python editor.
Typical steps:
- Type your Python code into the editor area.
- Press the Run Code button.
- Look at the output area to see what your program printed.
Output means "show something to the user".
In Python we use print():
print("Welcome to Python")
print("This is Lesson 1")
Each print() shows a new line.
You must put text inside quotes:
"Hello"is text (a string).Hellowithout quotes is treated as a name and will cause an error.
If there is a mistake in your code, Python may show an error message.
A syntax error happens when your code is written incorrectly, like a spelling or punctuation mistake. For example, forgetting quotes or brackets.
A bug is any problem that makes your code work the wrong way. Some bugs show error messages, but others are logic bugs, where the code runs but gives the wrong result.
Example 1 – Simple message
print("I am learning Python!")
Example 2 – Multiple lines
print("Line one")
print("Line two")
print("Line three")
Predict then run
Before running the code below, predict what will be printed. Then run it to check your answer.
Output
Example Solution
print("First line")
print("Second line")
print("Third line")
Try it yourself
Change the text so the program prints exactly three lines:
Line 1 must print: I am learning Python.
Line 2 must print: Python is fun to use.
Line 3 must print: I can write my own programs.
Output
Example Solution
print("Python is cool")
print("I can print messages")
print("On three different lines")
3. Input with input()
Input means “get data from the user”.
In Python we use input() with a message inside the brackets.
Python shows the message and waits for the user to type something and press Enter.
Example 3 – Ask for a name
name = input("What is your name? ")
print("Hello", name)
What happens:
input("What is your name? ")shows the question.- The user types their name.
- Python stores the answer in
name. print("Hello", name)shows a greeting.
Example 4 – Ask two questions
favourite_food = input("What is your favourite food? ")
pet = input("What is your pet's name? ")
print("Your pet", pet, "likes", favourite_food)
Try it yourself
Run the code, then change the messages and output to make another greeting.
Output
Example Solution
favourite_food = input("What is your favourite food? ")
pet = input("What is your pet's name? ")
print("Your pet", pet, "likes", favourite_food)
5. Understanding Quiz
Answer all questions below, then click "Check Answers" at the end to see your score.
Hello?print("A")
print("B")
print("Hello", "Sam")
print(name)
name = "Sam"
print("1")
name = input("Name: ")
print("2")
4. Coding tasks – Try it yourself
Complete all the tasks below. Do one task at a time, run your code, and check the output.
-
Task 1 – Two-line greeting
Write a program that:- Prints
Hello, world! - Prints
Welcome to Python.on the next line.
- Prints
-
Task 2 – Personal greeting
Write a program that:- Asks for the user's name using
input(). - Prints a greeting using their name, e.g.
Hello Sam.
- Asks for the user's name using
-
Task 3 – Favourite things
Write a program that:- Asks for the user's favourite subject.
- Asks for the user's favourite hobby.
- Prints two sentences using both answers, e.g.
You like Maths.andYou enjoy gaming.
-
Task 4 – Create your own questions
Write a program that:- Uses
input()three times to ask three questions. - Uses
print()once to display a sentence using the answers.
Example topics: an animal, a food, and a place.
- Uses
Answer all the above tasks here
Use the editor below to complete the coding tasks above.