Year 08_Computer Science Mrs.
Wissam
Constants in Programming
1. Definition:
A constant is a space in memory that stores a value that cannot be
changed while the program is running.
2. Purpose of Constants:
● Prevent accidental changes to important values.
● Simplify updates across the program.
● Reduce human error and save time in coding.
Example: Converting Miles to Kilometers
# Declare a constant
MULTIPLIER = 1.609
# Get input from the user
miles = float(input("Enter miles: "))
# Calculate and display the result
print("Kilometers:", miles * MULTIPLIER)
3. Difference Between Constants and Variables:
● Constant: A value that cannot be changed while the program is
running.
● Variable: A value that can change during the program's execution.
Instructions for Copybook Entry:
1. Write the date: Thursday, 7th November.
2. Write the title of the lesson: “Constants in Programming”
3. Copy the lesson summary into your copybooks.