Diko_player

๐Ÿ”ฐ Introduction :

The current image has no alternative text. The file name is: IMG_20250714_005716-1-scaled.jpg

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 ููŠ ู…ุง ูŠุฎุต ุงู„ุชุญู…ูŠู„ ููŠ ุฏุงูˆู†ู„ูˆุฏุฑ

โฌ‡๏ธ Download Diko ุชุญู…ูŠู„

Related Posts

Rapid_tv

๐Ÿ”น Introduction The Rock, Paper, Scissors Game is a classic hand game that you can easily build in Python. ๐Ÿ‘‰ Rules: ๐Ÿ”น Code Example ๐Ÿ”น Example Run ๐Ÿ”น Concepts Learned…

Read more

VOD-ZalHD

๐Ÿ”น Introduction The Number Guessing Game is a classic beginner Python project. ๐Ÿ”น Code Example ๐Ÿ”น Example Run ๐Ÿ”น Concepts Learned ๐Ÿ”น Summary โฌ‡๏ธ Download VOD-ZalHD ุชุญู…ูŠู„ Server 1 โฌ‡๏ธ…

Read more

Delux_pro

๐Ÿ”น Introduction The To-Do List App is one of the most popular beginner projects. It teaches you how to: ๐Ÿ”น Code Example ๐Ÿ”น Features of This App ๐Ÿ”น Example Run…

Read more

Fam4k

๐Ÿ”ฐ Project Overview A calculator is one of the simplest yet most effective projects to start with in Python.You will learn: โœ๏ธ Step 1: Plan the Calculator We need: ๐Ÿ–ฅ๏ธ…

Read more

Speed_HD+

1. Introduction Data visualization helps us understand patterns and insights in data by converting raw numbers into charts and graphs.In Python, the most popular libraries are: 2. Installing Required Libraries…

Read more

Dauo

1. Introduction Web scraping is the process of extracting data from websites. In Python, we commonly use libraries like requests (to fetch web pages) and BeautifulSoup (to parse and extract…

Read more