0% found this document useful (0 votes)
11 views

CIC Hands On Python - s1&2

Uploaded by

Ns Arial
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

CIC Hands On Python - s1&2

Uploaded by

Ns Arial
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Hands on

Python
Prepared by : Abdelaziz Shaheen
TABLE OF CONTENTS

01 03
Overview Setting Up the
Environment

02 04
Time Complexity Variables

Prepared by : Abdelaziz Shaheen


TABLE OF CONTENTS

05 07
Operators & Python
Conditional Functions

06 08
Loops ?

Prepared by : Abdelaziz Shaheen


01
OVERVIEW

Prepared by : Abdelaziz Shaheen


Let’s Answer Some
Questions!!

● What is a Computer?
● What is an Operating System?
● What is an Application?
● Open-Source Vs Close-Source Software

Prepared by : Abdelaziz Shaheen


Let’s Answer Some
Questions!!
● What is a Computer?
○ A computer is an electronic device that manipulates information, or data. It can store,
retrieve, and process data. You may already know that you can use a computer to type
documents, send email, play games, and browse the Web. You can also use it to edit or
create spreadsheets, presentations, and even videos.

● What is an Operating System?


● What is an Application?
● Open-Source Vs Close-Source Software

Prepared by : Abdelaziz Shaheen


Let’s Answer Some
Questions!!
● What is a Computer?
● What is an Operating System?
○ An operating system is the most important software that runs on a computer. It
manages the computer's memory and processes, as well as all of its software and
hardware. It also allows you to communicate with the computer without knowing how to
speak the computer's language. Without an operating system, a computer is useless.
○ The three most common operating systems for personal computers are Microsoft
Windows, macOS, and Linux.

● What is an Application?
● Open-Source Vs Close-Source Software

Prepared by : Abdelaziz Shaheen


Let’s Answer Some
Questions!!
● What is a Computer?
● What is an Operating System?
● What is an Application?
○ Simply put, an app is a type of software that allows you to perform specific tasks.
Applications for desktop or laptop computers are sometimes called desktop
applications, while those for mobile devices are called mobile apps.

○ When you open an application, it runs inside the operating system until you close it.
Most of the time, you will have more than one application open at the same time,
which is known as multi-tasking.

● Open-Source Vs Close-Source Software


Prepared by : Abdelaziz Shaheen
Let’s Answer Some
Questions!!
● What is a Computer?
● What is an Operating System?
● What is an Application?
● Open-Source Vs Close-Source Software
○ Assignment

Prepared by : Abdelaziz Shaheen


History of Python
● Python was created by Guido van Rossum
and was first released in 1991.
● The language's design philosophy
prioritizes code readability, and its
syntax allows programmers to express
concepts in fewer lines of code.

Prepared by : Abdelaziz Shaheen


WHY CHOOSE PYTHON
Readability and Community Support
Simplicity
Python has a large and active
Python's easy-to-read syntax allows community. This means extensive
developers to write clear and concise documentation, numerous tutorials,
code, enhancing productivity and and a wealth of resources to help
collaboration. developers solve problems.

Rapid Prototyping Job Opportunities


Python's simplicity and ease of use Python's popularity has led to an
make it an excellent choice for increasing demand for Python
prototyping and iterative developers across various
development. Developers can quickly industries, making it a valuable skill
test ideas and concepts. in the job market.

Prepared by : Abdelaziz Shaheen


Uses of Python

Web Data Automation and


Development Science Scripting

Python frameworks like Django Libraries like NumPy, Pandas, Python's simplicity and ease of
and Flask simplify web Matplotlib, and SciPy make use make it a favorite for
development tasks. Python a popular choice for data automation, scripting, and task
analysis and visualization. scheduling.

Game Desktop
Development Cybersecurity Applications

Pygame, a set of Python Python is used in cybersecurity Libraries like Tkinter and PyQt
modules, is used for writing for tasks like penetration allow developers to create
video games and multimedia testing, vulnerability scanning, cross-platform desktop
applications. and creating security tools. applications.

Prepared by : Abdelaziz Shaheen


NOT THE FASTEST ONE !!

Prepared by : Abdelaziz Shaheen


02
Time Complexity

Prepared by : Abdelaziz Shaheen


What is Time and Space Complexity?
• One major underlying factor affecting your program's performance
and efficiency is the hardware, OS, and CPU you use.
• An algorithm's time complexity specifies how long it will take to
execute an algorithm as a function of its input size. Similarly, an
algorithm's space complexity specifies the total amount of space
or memory required to execute an algorithm as a function of the
size of the input.

Prepared by : Abdelaziz Shaheen


Different Notations for
Time Complexity

- - -

Big O Upper Bound Worst Case Maximum

Omega Lower Bound Best Case Minimum

Theta Middle - -

Prepared by : Abdelaziz Shaheen


Big O Notation
Constant: O(1)

Linear Time: O(n)

Logarithmic Time: O(n log n)


Big O
Types of Complexities Quadratic Time: O(n^2)

Exponential Time: O(2^n)

Factorial Time: O(n!)

Prepared by : Abdelaziz Shaheen


Big O Notation
O(1)
Excellent/Best

O(log n)
Good

Big O O(n)
Types of Complexities Fair

O(n log n)
Bad

O(n^2), O(2^n)and O(n!)


Horrible/Worst

Prepared by : Abdelaziz Shaheen


Big O Notation

Big O
Types of Complexities

Prepared by : Abdelaziz Shaheen


Calculate The Complexity

O(1)

Prepared by : Abdelaziz Shaheen


Calculate The Complexity

O(n)

Prepared by : Abdelaziz Shaheen


Calculate The Complexity

O(n^2)

Prepared by : Abdelaziz Shaheen


Binary Search

O(log n) Prepared by : Abdelaziz Shaheen


Quiz 1

O(n^2) O(n log n)

7. How is time complexity measured?


1.By counting the number of algorithms in an algorithm.
2.By counting the number of primitive operations performed by the algorithm on a given input size.
3.By counting the size of data input to the algorithm.
4.None of the above

Prepared by : Abdelaziz Shaheen


Quiz 1

O(n^2) O(n log n)


7. How is time complexity measured?

By counting the number of primitive operations performed by the algorithm on a given input size.

Prepared by : Abdelaziz Shaheen


03
Setting Up the
Environment

Prepared by : Abdelaziz Shaheen


Setting Up Python Environment:
• Download the latest version of Python for your operating system
(Windows, macOS, or Linux). From “Python Downloads”
• Run the installer and make sure to check the box that says "Add
Python x.x to PATH" during installation. This makes it easier to run
Python from the command line.

Prepared by : Abdelaziz Shaheen


Setting Up Python Environment:
• Open a command prompt (Windows) or terminal (macOS/Linux).
• Run the following command

Prepared by : Abdelaziz Shaheen


Setting Up Python Environment:
• To Run a python file, you need to write this command

Prepared by : Abdelaziz Shaheen


Setting Up Python Environment:
• Here is Some Basic CMD Commands

Dir List all the files inside the current directory

mkdir <filename> Creates new directory inside the current


directory
cd Change Directory

echo text > filename.txt To Create text file that includes the written
text
cls Clears all the commands in the cmd

color Changes the text color of the cmd

Prepared by : Abdelaziz Shaheen


LAB 1

1. Create a New Folder and Name it


“Python Workshop” this will be
our workspace
2. Then Create A new Text File name
it main.py
3. Write the following line of Code
in your text file then Run the
code using CMD

Prepared by : Abdelaziz Shaheen


04
Variables

Prepared by : Abdelaziz Shaheen


Variables
In Python, variables are used to store and manipulate data. Unlike some other programming
languages, Python does not require explicit declaration of variables or their data types. When you
assign a value to a variable, Python automatically determines the variable type based on the
assigned value.

Int float str

bool List Tuple

Dictionary None

Prepared by : Abdelaziz Shaheen


Variables

Variables
Mapping Boolean& None
Numeric Types Sequence Types
Types Type

Int float str list Tuple Dict bool None

Prepared by : Abdelaziz Shaheen


Variables

• Variable Names: Variable names can contain letters (both uppercase and lowercase), digits, and
underscores (_). However, they cannot start with a digit. Variable names are case-sensitive (age
and Age would be different variables).
• Constants: While Python doesn't have constants in the strict sense, variables with all capital
letters (e.g., PI = 3.14) are often used to indicate that their values should not be changed.
• Multiple Assignment: You can assign values to multiple variables in a single line:
a, b, c = 1, 2, 3
• Variable Naming Convention: It is a common convention in Python to use snake_case for
variable names (e.g., user_age, total_count) to enhance readability.
• Deleting Variables: You can delete a variable using the del statement:
del age

Prepared by : Abdelaziz Shaheen


LAB 2

1. Write a code to calculate the


Area of a circle:
• radius = 20
• PI = 3.14
• Use the Naming conventions we
discussed previously.

Prepared by : Abdelaziz Shaheen


Python Input & Output
Input: input() Output : Print()

input (): This function first takes the input from


the user and converts it into a string. The type of
the returned object always will be <class ‘str’>.
It does not evaluate the expression it just
returns the complete statement as String. For
example, Python provides a built-in function
called input which takes the input from the user.
When the input function is called it stops the
program and waits for the user’s input. When the
user presses enter, the program resumes and
returns what the user typed.

Prepared by : Abdelaziz Shaheen


String
A String in Python is a Sequence of Characters

Python Uses Single Quotes ‘ ’ and double Quotes “ ” but it’s preferred to use the single one

Escaping

Prepared by : Abdelaziz Shaheen


String Operations
Strings come with several handy, built-in operations you can execute. You can find all the operations
you need in Official Python Manual

Prepared by : Abdelaziz Shaheen


Python Tuple
We create tuples from individual values using optional parentheses (round brackets) like this:

Multiple Assignment Indexed Access

Prepared by : Abdelaziz Shaheen


Python List
Lists contain regular Python objects, separated by commas and surrounded by brackets. The elements
in a list can have any data type, and they can be mixed. You can even create a list of lists

Using the list() function

Prepared by : Abdelaziz Shaheen


List Vs Tuple
The most significant difference between a Python tuple and a Python list is that a List is mutable,
while a tuple is not. After defining a tuple, you can not add or remove values. In contrast, a list
allows you to add or remove values at will. This property can be an advantage; you can see it as
write protection. If a piece of data is not meant to change, using a tuple can prevent errors. After
all, six months from now, you might have forgotten that you should not change the data. Using a
tuple prevents mistakes.

Prepared by : Abdelaziz Shaheen


Python Dictionary
A dictionary is created by using curly braces. Inside these braces, we can add one or more key-value
pairs. The pairs are separated by commas when adding more than one key-value pair. The first
dictionary in our example associates keys (names like Jack and Pete) with values (their phone
numbers). The second dictionary is an empty one.

Prepared by : Abdelaziz Shaheen


Python Dictionary
A dictionary is created by using curly braces. Inside these braces, we can add one or more key-value
pairs. The pairs are separated by commas when adding more than one key-value pair. The first
dictionary in our example associates keys (names like Jack and Pete) with values (their phone
numbers). The second dictionary is an empty one.

Prepared by : Abdelaziz Shaheen


Python Dictionary
Access and delete a key-value pair

Default values and dict.get()

Prepared by : Abdelaziz Shaheen


05
Operators &
Conditional

Prepared by : Abdelaziz Shaheen


Comparison Operators

Operator Meaning

> Greater than

< Smaller Than

>= G or equal

<= S or equal

== Is equal

!= Is not equal

Prepared by : Abdelaziz Shaheen


Logical Operators

Operator What is does

And True if both


statements are true

or True if one of the


statements are true

Not Negates the


statement that
follows

Prepared by : Abdelaziz Shaheen


IF Statement

Prepared by : Abdelaziz Shaheen


IF…else Statement

Prepared by : Abdelaziz Shaheen


LAB 3

Create a code that checks if the


input email Is valid or not

1. “@gmail.com”.
2. You need to make all the letters
lowercase.
3. The email can not start with a
number. *

Prepared by : Abdelaziz Shaheen

You might also like