๐ฐ Introduction :

In the previous lesson, we learned about the importance of programming and wrote our first code to print “Hello, World!”
In this lesson, we’ll actually start writing small programs and learn basic concepts like variables and data types, which are the foundation of any programming language.
๐งฉ What is a Variable ?
A variable is a “container” into which we store information we need later. For example:
Python
name = “Ali”
age = 25
name and age are variables.
“Ali” is a string, and 25 is an integer.
๐ Once a value is stored in a variable, you can use it later within your program.
๐งฎ Basic Data Types in Python:
Data Type Description Example
Strings: Texts between double quotes: “hello”, ‘Ali’
Integers: Integers without commas: 5, 100
Floats: Integers with commas: 3.14, 99.9
Bools: True or False
๐งโ๐ป Printing Information :
python
name = “Sara”
print(“Hello, ” + name)
๐ When using + between strings, they are combined into a single result.
โ๏ธ User Input :
python
city = input(“What city are you from?”)
print(“Hello, from ” + city + “!”)
๐น input() makes the user type something into the program.
๐ง Exercise 1 :
Write a program that asks the user for their name and age, then prints a welcome message:
python
name = input(“What’s your name?”)
age = input(“How old are you?”)
print(“Hello, ” + name + “! Your age is ” + age + ” years.”)
๐ The output could be :
What’s your name ? Youssef
How old are you ? 22
Hello, Youssef! Your age is 22 years.
โ ๏ธ Important note :
Everything entered using input() is considered a string, even if the user types a number.
Example :
python
age = input(“Enter your age: “)
print(age + 5) # โ An error will appear!
So we need to convert it to an integer:
python
age = int(input(“Enter your age: “))
print(age + 5) # โ Now it works!
๐ง Exercise 2 :
Simple Addition Machine
Write a program that asks the user for two numbers and then displays the result of adding them:
python
num1 = float(input(“Enter the first number: “))
num2 = float(input(“Enter the second number: “))
result = num1 + num2
print(“The result is: ” + str(result))
๐ข We used float to support decimal numbers, and str() to convert the result to text.
๐งช Additional Challenge :
Write a program that asks the user for:
His name
His age
His city
The city he lives in
Then it prints this sentence :
“Hello [name], you are [age] years old and live in [city]!”
๐ Summary :
I learned about variables and basic data types.
I used input() to read data from the user.
I used print() to print the results.
I started thinking about basic programming logic.
๐ What will we learn in Lesson 3 ?
In the next lesson, we will delve into the world of program flow control using conditions, and learn how to make our program interact intelligently with the user using if, else, and elif statements.
How to download in google chrome ุทุฑููุฉ ุงูุชุญู ูู ูู
Regarding downloading in Downloader ูู ู ุง ูุฎุต ุงูุชุญู ูู ูู ุฏุงููููุฏุฑ