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

FivG_Pro

๐Ÿ”ฐ What Is a Function? A function is a reusable block of code that performs a specific task.Instead of repeating code, we can write it once and call it whenever…

Read more

Show7_Pro

๐ŸŸข Lesson 6 โ€“ Intermediate Level ๐Ÿ”ฐ What Is a Module? A module is simply a Python file (.py) containing code (functions, variables, classes) you can reuse in other programs….

Read more

GoldiptvPro

๐ŸŸข Lesson 5 โ€“ Intermediate Level ๐Ÿ”ฐ What Are Exceptions? An exception is an error that occurs during the execution of a program.If not handled, it will stop the program…

Read more

Domingo

๐ŸŸข Lesson 4 ๐Ÿ”ฐ What Is OOP? Object-Oriented Programming (OOP) is a programming style where you organize code into objects that contain: Python supports OOP using: ๐Ÿงฑ Example: Why Use…

Read more

SHARK_PRO

๐Ÿ”ฐ What Is File Handling? ๐ŸŸข Lesson 3 File handling lets your Python programs interact with files on your computer โ€” read data from them or save data to them….

Read more

ZinaTv

๐ŸŸข Lesson 2 โ€“ Intermediate Level ๐Ÿ”น Python Dictionaries: Storing and Accessing Key-Value Data ๐Ÿ”ฐ What Is a Dictionary? A dictionary in Python is a data structure that stores data…

Read more