0% found this document useful (0 votes)
9 views20 pages

Python Basics: Syntax and Examples

The document provides an introduction to Python programming, explaining its purpose as a computer language that uses code to instruct computers. It covers basic concepts such as print statements, input functions, variables, conditional statements (if-elif-else), and for loops, along with examples and exercises for practice. The content is aimed at beginners learning to program in Python.

Uploaded by

cchristidis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views20 pages

Python Basics: Syntax and Examples

The document provides an introduction to Python programming, explaining its purpose as a computer language that uses code to instruct computers. It covers basic concepts such as print statements, input functions, variables, conditional statements (if-elif-else), and for loops, along with examples and exercises for practice. The content is aimed at beginners learning to program in Python.

Uploaded by

cchristidis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

What is

Python ?
Learning Points

is p yt ho n
what
h a t w e The syntax am ple + min
and w Ex
can c re a t e of Python pro jec t
with it
Definition
Python is a kind of computer language — but instead of using words
like people do, it uses code that tells the computer what to do.
You can think of Python like giving instructions to a robot.
For example:
You can tell it to add two numbers.
You can tell it to draw a picture.
You can even tell it to make a game or a website!
The
Print()
Input ()
Syntax Variable
If elif else
In for loop

Pyton
Print
In Python, print is a command we
use to show messages, numbers,
or answers on the screen.
It’s like asking the computer to
speak whatever you put inside the
print(...), the computer will show it.
Ex: print(“hello world”)
=> hello world
Exercises of
1. Print your
Print ()
4. Print:
name using
Please enter
print(). [Link]: [Link]: Your your PIN.
Welcome to balance is
Python! $100.
Correction of
Print ()
1. print(“Jad”) 4. Print(“
Please enter
2. Print(“ 3. Print(“ Your your PIN.”)
Welcome to balance is
Python!”) $100.”)
Input()
In Python, input is used when we want the computer to ask the
user a question and wait for an answer.
It’s like the computer saying:
“Hey! Tell me something!”
Then you type your answer, and the computer can use it later.
•Example: name = input(“Enter your name: “)
int() stands for integer, which means a whole number
Ex: number=int(input(“Enter a number:”))
Exercises of
1. Ask the user
Input()
•4. Ask for the
to enter their
amount to
name. 2. Ask the 3. Ask for the deposit.
user to enter amount to
their PIN. withdraw.
Correction of
Input()

1. print(“enter your name”) 3. print(“enter your withdraw”)


name=input() withdraw=int(input())

2. print(“enter a pin”) 4. print(“enter your deposit”)


pin=input() deposit=int(input())
Variable
A variable is like a box where you can store information — such
as a number, a word, or anything you want the computer to
remember.
You give each box a name, so you can use it later in your
program.
Ex: name=”fady”
print(name)
=> fady
Exercises of
1. Create a Variable
variable called 4. Print your
balance = 500 variables.
2. Create a 3. Create a
variable pin variable
= 1234. name = 'Alex'.
Correction of
Variable
1. balance = 500 4. name=”alex”
print(name)

[Link] = 1234.
[Link] = “Alex”.
When you make choices in real life — like “If it’s raining, I’ll take
an umbrella. If it’s sunny, I’ll wear sunglasses. Otherwise, I’ll just
go out.”

if checks if something is true
elif (means else if)→ checks another thing if the first one
wasn’t true
else → runs if nothing above was true
Ex : age = int(input("How old are you? "))
if age < 13:
print("You are a child.")
elif age < 18:
print("You are a teenager.") if else
else:
print("You are an adult.")
Exercise of
if else

1. Ask the user for the


temperature and print
whether it’s hot, warm, or cold.

2. Ask the user for their age


and tell them if they are
a child, teenager, or adult.
Correction of
if else
1. temperature = int(input("Enter [Link] = int(input("Enter your
the temperature: ")) age: "))
if temperature > 30: if age < 13:
print("It's hot!") print("You are a child.")
elif temperature >= 20: elif age < 18:
print("It's warm.") print("You are a teenager.")
else: else:
print("It's cold.") print("You are an adult.")
For loop
A for loop is a way to tell the computer:
“Do this again and again for a certain number of times.”
It helps you repeat actions without writing the same code many
times.
Ex:for i in range(5):
print("Hello!")
The computer says “Hello!” 5 times.
Exercises of
For loop
2. Ask the user for a number,
1. Make the computer
then show its multiplication
print the numbers 1 to
table!
10 using a for loop.
Correctio of
n
For loop
1. for i in range(1, 11):
print(i)

2. number = int(input("Enter a number: "))


for i in range(1, 11):
print(number, "x", i, "=", number * i)
Thanks for

listening !

You might also like