LESSON 3
Lesson Objectives
- The need for variables in digital systems
- To be able to explain what the use of variables
- How to prompt the user for data and assign it to a variable.
Success Criteria
- I understand what a variable is
- I know how to assign data to a variable
- I can use the input() function to captures user’s keyed in data.
Keywords
- String
- Variable
- Assign
Commands
- input()
- int()
- print()
Starter
Discuss with the person next to you what is the difference between Interactive Mode (SHELL) and Script Mode
(hint: we use one of these to write larger and more complex programs).
When you are on interactive mode if you click File then New Window you will open below script mode window.
Task 2
Open your Python program from start button > all apps > Python 3.1 > select IDLE (Python GUI)
Write the below code in Script Mode, save it as hello.py and run it to see what happens.
Task 3
Explain in your book what do you think “name”, “year” and “age” do in above code?
Task 4
Complete below sentence in your book with your own words.
A variable is …
Task 5
Edit your program further by adding a new variable which will be assign to users favourite food.
You need to create a new variable called favourite_food by asking an input from a user to enter their favourite food
and you need to write a new line to output with their name, “Ah, your favourite food is” …
Save it and then Run it (F5)
Task 6 – QUESTIONS … you have 2 minutes!
Answer below questions in your book. Make sure you write Task 6 (you do not need to write the each question)
- Write down the name of a variables used in the above program
- How many variables are used in the above program
- What kind of character/symbol is used to assign values to a variable
- Write down an example of assignment
- Katie is writing her first program. It won’t run properly. Can you spot the Syntax error?
Print(‘Hello World’)
Challenge Task
Create a program in python that prompts the user for their name AND the names of their top 5 favourite films. Each film should be assigned to a separate variable. When run, the computer should output the following…