You are on page 1of 13

07/04/2024

Python - Variables
Aim: Key Words:
Input
• Understand Variables & Inputs Process
Outcomes To Be Able To: Output
Variable
1. Explain what a variable is Input
2. List the types of variable in Python Value
Name
3. Create variables for users Data type
4. Link strings and variables using Concatenation
Syntax
concatenation String
5. Produce outputs using strings and Integer
variables Float
Boolean
Computer Programs

Input Process Output

• To be useful must have the following steps:


• INPUT – Variables - text, numbers, yes, no
• Process – calculations, sorting, searching
• Output – Print
Lets Run Some Code
T Drive – complement code

• This program only has an OUTPUT


• A good program Needs an INPUT/PROCESS/OUTPUT
• print is an Output as it sends the data to the screen
• There are no Inputs or process steps so the program
can only do one thing
Lets Introduce Variables

• We now have 2 Variables whose NAMES are:


• fname
• sname
Variables
• A Variable is a stored value that has a
• Name fname & sname
• Data type string (text)
• Value Fred & Smith
Lets Add Some Processing & Output

• We now have 2 inputs fname & sname


• Two outputs both the print statements
• What do the +’s do?
• They process data – add the variables to our string
The Whole Program

• Variable Names
• Data Type – String (text or any value on a keyboard)
• Values e.g. Mary Jones
Data Types
• Char – one character
• String – text(i.e. more than one character)
• Integer – real numbers (whole numbers)
• Float – decimal numbers
• Boolean – True or False – Yes or No
Syntax – try this:

• Syntax refers to the correct use of Python spelling and


grammar
• In this case print is spelt incorrectly as in has a capital P.
• In computer science, the syntax of a computer language is
the set of rules that defines the combinations of symbols that
are considered to be a correctly structured document or
fragment in that language.
Task How to make a complement
• Write a program that asks for a users
• First Name,
• Surname,
• Hair Colour
• And outputs the following string:
• Hi my name is your name, First Name,
Surname, you have beautiful Hair Colour hair.
10 Second Rule Game
1. What 3 steps must a computer program have to be useful?
2. Give an example of an input?
3. Give an example of an output?
4. Give an example of a process?
5. What 3 factors/parts make up a variable?
6. What is the name given to the datatype for text?
7. What datatype is char?
8. What is the name given to the datatype for whole numbers?
9. What is the name of the datatype for decimals e.g. 0.9999
10. What is the name given to the datatype True/False or Yes/No?
11. What would be a good variable name to ask someone their name?
12. What does syntax mean?
13. What is wrong with this code: PRINT(“Hi my name is fred”)
14. What is the name of the process of adding variables to strings?
07/04/2024

Python - Variables
Aim: Key Words:
Concatenation
• Understand Variables & Inputs Input
Outcomes To Be Able To: Process
Output
1. Explain what a variable is Syntax
2. List the types of variable in Python Variable
Value
3. Create variables for users Name
4. Link strings and variables using Data type
Value
concatenation String
5. Produce outputs using strings and Integer
variables Float
Boolean
Homework
• Visit https://repl.it/languages/python3
• And get the following code to work:

Note the indent. This is 4 spaces


You will need to add a Variable & Input

You might also like