Ict assignment
Ict assignment
1. What is a variable?
A variable: is a name used to store data in a program. It acts like a container that holds
information which can change during the program.
For example:
age = 18
Here, age is a variable that stores the value 18.
2. What is an Identifier?
An identifier is the name used to identify variables, functions, classes, modules, etc. It must
follow certain rules like:
A data type tells us what kind of data a variable holds. Python has different data types like:
-.Integer (int)
-.Floating-point (float)
-.String (str)
Example:
name = "Betigist" —-------------- string type
age = 18 —------------------- integer type
height = 1.75 —------------------ float type
Floating numbers (floats) are numbers with decimal points. They are used when we want
more precious than whole number.
In Python, this type is called float.
Example:-
pi= 3.14
weight = 52.5
Built-in data types: are types that Python already provides. Common ones include:
●. int for whole numbers
●. float for decimal numbers
●. str for text (string)
●. bool for true/false
●. list, tuple, dict, set for collections of data
6. Use print() function and display my name "Betigist Yemane" on the screen using
interactive interpreter
In the interactive interpreter (like the Python shell), you just type this and press Enter:
print("Betigist Yemane")
7. What is the difference between Python’s interactive interpreter and text editor?
Interactive interpreter:- lets you run one line at a time and see the result immediately. It is
useful for quick tests.
Text editor:- is used to write full Python programs saved in .py files. You run the whole
program after writing.
8. Use the print() function to display my name "Betigist Yemane" on the screen using
text-editor
In a text editor, write the following in a file (like myname.py):
print("Betigist Yemane")
9. Identify the valid identifiers and explain why they are so:
Let’s analyze each one:
Modulus (%)
-.This gives the remainder after dividing two numbers.
Example: 7 % 2 gives 1.
It is commonly used to check if a number is even or odd.
Concatenation (+)
-. The + operator joins two strings together.
Example: "Hello " + "Betigist" becomes "Hello Betigist".
It is only used with text (strings), not with numbers in this case.
Exponentiation (**)
-. This operator raises a number to the power of another.
Example: 2 ** 3 means 2³, which equals 8.
It is used when you want to multiply a number by itself multiple times.
11. Define data type conversion and list the two types:
Data type conversion means changing one data type into another.
In Python, you might change a number to a string or vice versa.
-.Explicit Conversion
You convert data types yourself using functions like int(), str(), or float().
Example: age = int("18") changes the string "18" to the number 18.
Statements do something;
Expressions produce something.
x=4*3 # Statement
y = "Programming is fun" # Statement
print(y) # Statement
z=x/2 # Statement
print(z) # Statement
y = 10 # Statement
print(type(x)) # Statement
Only the lines that use print() will show something on the screen.
-.print(y)
-.print(z)
-.print(type(x))
17.When the code given in activity 16 is executed, what would be the out-put on the
screen?
This code asks the user for two numbers and shows the multiplication result.