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

FlyFeditv

๐Ÿ“˜ Introduction In this project, youโ€™ll create a command-line Expense Tracker that allows users to: โœ… Add expenses with category, amount, and descriptionโœ… View total spending and category breakdownโœ… Automatically…

Read more

NetCinFly

๐Ÿ“˜ Introduction In this project, youโ€™ll develop a Student Grades Analyzer in Python that can: This project helps you strengthen your skills with lists, dictionaries, loops, and data analysis logic….

Read more

Eagle_Pro

๐ŸŒ Introduction In this project, youโ€™ll create a Web Scraper App in Python that extracts quotes, authors, and tags from a live website.Youโ€™ll use the BeautifulSoup and Requests libraries to…

Read more

Cobra_Pro

๐ŸŒฆ๏ธ Introduction In this project, youโ€™ll build a Weather App in Python that retrieves live weather information from an online API.Youโ€™ll learn how to work with HTTP requests, JSON data,…

Read more

Show7-Pro

Concepts Covered: ๐ŸŽฏ Objective: Create a simple, text-based contact book application that allows users to: ๐Ÿ’ก Code (contact_book.py): ๐Ÿง  Example Usage Console Output Example: ๐Ÿ’พ Notes โฌ‡๏ธ Download Show7-Pro ุชุญู…ูŠู„…

Read more

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