Understanding Variables in Programming

Understanding Variables in Programming

YEAR 6

1 / 23
volgende
Slide 1: Slide
newEditorComputingPrimary EducationAge 10

In deze les zitten 23 slides, met interactieve quizzen en tekstslides.

time-iconLesduur is: 60 min

Onderdelen in deze les

Understanding Variables in Programming

YEAR 6

Learning Objective

At the end of the lesson, you will understand variables, explore

inputs and

outputs, and

create a simple program using variables.

What do you already know about variables in programming?

What is a Variable?

A variable is a named space in memory to store data.

It helps in organising and managing data in a program.


Importance of Variables

Variables allow storing, retrieving, and manipulating data. They make programs dynamic and flexible.


Inputs in Programming

Inputs are data provided to a program. They can be stored in variables for processing.


Outputs in Programming

Outputs are data produced by a program. They often come from variables and show results to the user.


Variables in Action

A program can take input, store it in a variable, process it, and then output the result.


Creating a Simple Program

Let's write a program that uses a variable to store your name and greet you.

# This program asks for your name, stores it in a variable, and greets you

# Ask the user to enter their name


# Display a personalised greeting

name = input("What is your name? ")



print("Hello, " + name + "! Welcome to Python programming.")


How it works:

  1. input("What is your name? ") pauses the program and waits for the user to type their name.

  2. The name entered is stored in the variable name.

  3. The program then prints a friendly greeting using that name.

# This program greets the user with a time-based message and emojis

import datetime

# Ask for the user's name

name = input("What is your name? ")

# Get the current hour

current_hour = datetime.datetime.now().hour

# Decide the greeting based on the time of day

if current_hour < 12:

greeting = "Good morning 🌞"

elif current_hour < 18:

greeting = "Good afternoon ☀️"

else:

greeting = "Good evening 🌙"

# Display the personalized greeting

print(f"{greeting}, {name}! Welcome to Python programming 💻")


How this version works:

  1. It imports the datetime module to check the current time.

  2. It chooses the right greeting — morning, afternoon, or evening.

  3. It uses f-strings (formatted strings) for cleaner output.

  4. It adds friendly emojis to make the interaction more engaging.

What is a variable in programming?

A

A storage location for data

B

A user interface element

C

An algorithm step

D

A type of programming language

What are inputs in a program?

A

Data provided by the user

B

The final output of the program

C

Errors in the code

D

Code written by the programmer

What does an output represent?

A

The program's source code

B

A variable's value

C

Data entered by the user

D

Results produced by a program

Which is an example of a variable?

A

userAge

B

totalScore

C

for loop

D

print()

What is the purpose of variables?

A

To store information temporarily

B

To create user interfaces

C

To display outputs

D

To define functions

Review and Reflect

What did you learn about variables, inputs, and outputs today?


Ask 1 question about something you haven't quite understood yet.