0% found this document useful (0 votes)
3 views1 page

Constants in Programming

The document explains constants in programming, defining them as unchangeable values in memory that help prevent accidental changes and reduce coding errors. It includes an example of converting miles to kilometers using a constant multiplier. Additionally, it distinguishes between constants and variables, highlighting that constants remain fixed while variables can change during execution.

Uploaded by

moham4d2023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Constants in Programming

The document explains constants in programming, defining them as unchangeable values in memory that help prevent accidental changes and reduce coding errors. It includes an example of converting miles to kilometers using a constant multiplier. Additionally, it distinguishes between constants and variables, highlighting that constants remain fixed while variables can change during execution.

Uploaded by

moham4d2023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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.

You might also like