SlideShare une entreprise Scribd logo
1  sur  24
PYTHON FOR ETHICAL HACKERS
Mohammad reza Kamalifard
Python Language Essentials
Part 4 :
Conditional Statements
if Statement
Like if in other languages but second if called elif
if test_condition1:
do stuff
do stuff
elif test_condition2:
do stuff
do stuff
elif test_condition3:
do stuff
do stuff
else:
do stuff
Python Indentation
• Python uses whitespace indentation, rather than curly braces
or keywords, to delimit blocks; a feature also termed the off-
side rule.
• An increase in indentation comes after certain statements; a
decrease in indentation signifies the end of the current block.
C, C++
#include <iostream>
using namespace std;
int main(){
cout<<"Hello, World!";
return 0;
}
C, C++
#include <iostream>
using namespace std;int
main(){cout<<"Hello,World!";return 0;}
Indentation
if name == 'ali':
print 'Your name is ali'
Print ‘Always print this line‘
• 4 space
• Tab
• Google use 2 space
• We use 4 space (PEP 8)
$ vim if_statement.py
#!/usr/bin/env python
name = raw_input('Please Enter Your name! : ')
if name == 'reza':
print 'You are reza'
print 'And a course instructor'
elif name == 'Arman':
print 'You are Arman'
print 'And a student'
else:
print 'I don't know you‘
~
~
~
$ chmod a+x if_statement.py
$ ./if_statement.py
Please Enter Your name! : reza
You are reza
And a course instructor
$
$ ./if_statement.py
Please Enter Your name! : ali
I don’t know you
$
$ ./if_statement.py
Please Enter Your name! : Arman
You are Arman
And a student
$
While Loops
while statement_is_true:
do stuff
do stuff
break : get out if innermost loop
continue : start the next pass of the innermost
pass : do nothing, placeholder
$ vim while_statement.py
#!/usr/bin/env python
age = int(raw_input('Please Enter Your age ? : '))
while age > 10:
print 'You age is grater than 10'
~
~
~
$ chmod a+x while_statement.py
$ ./ while_statement.py
Please Enter Your age ? : 23
You age is grater than 10
You age is grater than 10
You age is grater than 10
You age is grater than 10
You age is grater than 10
You age is grater than 10
You age is grater than 10
You age is grater than 10
You age is grater than 10
You age is grater than 10
You age is grater than 10
You age is grater than 10
You age is grater than 10
You age is grater than 10
You age is grater than 10
You age is grater than 10
$ vim while_statement.py
#!/usr/bin/env python
age = 20
while age > 10:
age = int(raw_input('Please Enter Your age ? : '))
print 'You age is grater than 10'
~
~
~
$ chmod a+x while_statement.py
$ ./ while_statement.py
Please Enter Your age ? : 23
You age is grater than 10
Please Enter Your age ? : 15
You age is grater than 10
Please Enter Your age ? : 18
You age is grater than 10
Please Enter Your age ? : 8
You age is grater than 10
$
$ vim while_statement.py
#!/usr/bin/env python
age = 20
while age > 10:
age = int(raw_input('Please Enter Your age ? : '))
if age > 10:
print 'Your age is grater than 10'
elif age < 10:
print 'Your age is smaller than 10'
else:
print 'Your age is equal to 10'
~
~
$ chmod a+x while_statement.py
$ ./ while_statement.py
Please Enter Your age ? : 23
You age is grater than 10
Please Enter Your age ? : 15
You age is grater than 10
Please Enter Your age ? : 8
You age is smaller than 10
$
$ ./ while_statement.py
Please Enter Your age ? : 17
You age is grater than 10
Please Enter Your age ? : 10
You age is equal to 10
$
For Loops
for item in object:
do stuff
do stuff
for item in [1, 2, 3]
for item in ['a', 2, '3']
for (x,y) in [('reza', 23), ('mohammad', 25)]
>>> for item in [1, 2, 3]:
... print item
...
1
2
3
item is a name can be anything
>>> names = ['Reza', 'Majid', 'Sara', 'Iman']
>>> names
['Reza', 'Majid', 'Sara', 'Iman']
>>> for name in names:
... print name
...
Reza
Majid
Sara
Iman
>>>
>>> info = [('Reza', 23), ('Sara', 20), ('Shayan', 30),
('AmirAli', 21)]
>>> info
[('Reza', 23), ('Sara', 20), ('Shayan', 30), ('AmirAli', 21)]
>>> for (name, age) in info:
... print 'Your name is : %s and Your age is %d' % (name,
age)
...
Your name is : Reza and Your age is 23
Your name is : Sara and Your age is 20
Your name is : Shayan and Your age is 30
Your name is : AmirAli and Your age is 21
>>>
Emulating C style for loops
C style loops : for(i=0; i<10; i++)
for(i=0; i<10; i++){
cout<<i<<',';
}
0,1,2,3,4,5,6,7,8,9,
range()
range(lower, upper, step)
create a list for use
range(n) – [0,...,n-1]
>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>
>>> range(1,10)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> range(1,10,2)
[1, 3, 5, 7, 9]
>>>
>>> for number in range(1,10,2):
... print number
...
1
3
5
7
9
>>>
References
• Data model — Python v2.7.5 documentation
• http://docs.python.org/2/reference/datamodel.html#objects-values-and-types
• PEP 8 -- Style Guide for Python Code
• http://www.python.org/dev/peps/pep-0008/
THIS IS A COPYRIGHTED MATERIAL
©2013 Mohammad Reza Kamalifard.
ALL RIGHTS RESERVED.

Contenu connexe

Similaire à PYTHON FOR ETHICAL HACKERS CONDITIONAL STATEMENTS

Similaire à PYTHON FOR ETHICAL HACKERS CONDITIONAL STATEMENTS (20)

Python slide
Python slidePython slide
Python slide
 
An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutes
 
groovy & grails - lecture 3
groovy & grails - lecture 3groovy & grails - lecture 3
groovy & grails - lecture 3
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Python 1
Python 1Python 1
Python 1
 
Zen and the Art of Python
Zen and the Art of PythonZen and the Art of Python
Zen and the Art of Python
 
Python
PythonPython
Python
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School Programmers
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽
 
python chapter 1
python chapter 1python chapter 1
python chapter 1
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2
 
Python Part 1
Python Part 1Python Part 1
Python Part 1
 
Python Basic
Python BasicPython Basic
Python Basic
 
Python
PythonPython
Python
 
Python
PythonPython
Python
 
Learn python in 20 minutes
Learn python in 20 minutesLearn python in 20 minutes
Learn python in 20 minutes
 
NUS iOS Swift Talk
NUS iOS Swift TalkNUS iOS Swift Talk
NUS iOS Swift Talk
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
 

Plus de Mohammad Reza Kamalifard

Tehlug 26 Nov 2013 Hackers,Cyberwarfare and Online privacy
Tehlug 26 Nov 2013 Hackers,Cyberwarfare and Online privacyTehlug 26 Nov 2013 Hackers,Cyberwarfare and Online privacy
Tehlug 26 Nov 2013 Hackers,Cyberwarfare and Online privacyMohammad Reza Kamalifard
 
جلسه دوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه دوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲جلسه دوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه دوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲Mohammad Reza Kamalifard
 
جلسه سوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه سوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲جلسه سوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه سوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲Mohammad Reza Kamalifard
 
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱Mohammad Reza Kamalifard
 
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲Mohammad Reza Kamalifard
 
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱Mohammad Reza Kamalifard
 
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲Mohammad Reza Kamalifard
 
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲Mohammad Reza Kamalifard
 
اسلاید اول جلسه اول دوره پاییز کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه اول دوره پاییز کلاس پایتون برای هکرهای قانونیاسلاید اول جلسه اول دوره پاییز کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه اول دوره پاییز کلاس پایتون برای هکرهای قانونیMohammad Reza Kamalifard
 
اسلاید دوم جلسه یازدهم کلاس پایتون برای هکر های قانونی
اسلاید دوم جلسه یازدهم کلاس پایتون برای هکر های قانونیاسلاید دوم جلسه یازدهم کلاس پایتون برای هکر های قانونی
اسلاید دوم جلسه یازدهم کلاس پایتون برای هکر های قانونیMohammad Reza Kamalifard
 
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونیاسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونیMohammad Reza Kamalifard
 
اسلاید ارائه دوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه دوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی اسلاید ارائه دوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه دوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی Mohammad Reza Kamalifard
 
اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی Mohammad Reza Kamalifard
 
اسلاید ارائه سوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه سوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی اسلاید ارائه سوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه سوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی Mohammad Reza Kamalifard
 
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونیاسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونیMohammad Reza Kamalifard
 
اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونیاسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونیMohammad Reza Kamalifard
 
اسلاید سوم جلسه هفتم کلاس پایتون برای هکرهای قانونی
اسلاید سوم جلسه هفتم کلاس پایتون برای هکرهای قانونیاسلاید سوم جلسه هفتم کلاس پایتون برای هکرهای قانونی
اسلاید سوم جلسه هفتم کلاس پایتون برای هکرهای قانونیMohammad Reza Kamalifard
 

Plus de Mohammad Reza Kamalifard (20)

Internet Age
Internet AgeInternet Age
Internet Age
 
Introduction to Flask Micro Framework
Introduction to Flask Micro FrameworkIntroduction to Flask Micro Framework
Introduction to Flask Micro Framework
 
Pycon - Python for ethical hackers
Pycon - Python for ethical hackers Pycon - Python for ethical hackers
Pycon - Python for ethical hackers
 
Tehlug 26 Nov 2013 Hackers,Cyberwarfare and Online privacy
Tehlug 26 Nov 2013 Hackers,Cyberwarfare and Online privacyTehlug 26 Nov 2013 Hackers,Cyberwarfare and Online privacy
Tehlug 26 Nov 2013 Hackers,Cyberwarfare and Online privacy
 
جلسه دوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه دوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲جلسه دوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه دوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
 
جلسه سوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه سوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲جلسه سوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه سوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
 
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
 
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
 
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
 
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
 
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
 
اسلاید اول جلسه اول دوره پاییز کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه اول دوره پاییز کلاس پایتون برای هکرهای قانونیاسلاید اول جلسه اول دوره پاییز کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه اول دوره پاییز کلاس پایتون برای هکرهای قانونی
 
اسلاید دوم جلسه یازدهم کلاس پایتون برای هکر های قانونی
اسلاید دوم جلسه یازدهم کلاس پایتون برای هکر های قانونیاسلاید دوم جلسه یازدهم کلاس پایتون برای هکر های قانونی
اسلاید دوم جلسه یازدهم کلاس پایتون برای هکر های قانونی
 
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونیاسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
 
اسلاید ارائه دوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه دوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی اسلاید ارائه دوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه دوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
 
اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی
 
اسلاید ارائه سوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه سوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی اسلاید ارائه سوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه سوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
 
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونیاسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
 
اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونیاسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی
 
اسلاید سوم جلسه هفتم کلاس پایتون برای هکرهای قانونی
اسلاید سوم جلسه هفتم کلاس پایتون برای هکرهای قانونیاسلاید سوم جلسه هفتم کلاس پایتون برای هکرهای قانونی
اسلاید سوم جلسه هفتم کلاس پایتون برای هکرهای قانونی
 

Dernier

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Dernier (20)

Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 

PYTHON FOR ETHICAL HACKERS CONDITIONAL STATEMENTS

  • 1. PYTHON FOR ETHICAL HACKERS Mohammad reza Kamalifard
  • 2. Python Language Essentials Part 4 : Conditional Statements
  • 3. if Statement Like if in other languages but second if called elif if test_condition1: do stuff do stuff elif test_condition2: do stuff do stuff elif test_condition3: do stuff do stuff else: do stuff
  • 4. Python Indentation • Python uses whitespace indentation, rather than curly braces or keywords, to delimit blocks; a feature also termed the off- side rule. • An increase in indentation comes after certain statements; a decrease in indentation signifies the end of the current block.
  • 5. C, C++ #include <iostream> using namespace std; int main(){ cout<<"Hello, World!"; return 0; }
  • 6. C, C++ #include <iostream> using namespace std;int main(){cout<<"Hello,World!";return 0;}
  • 7. Indentation if name == 'ali': print 'Your name is ali' Print ‘Always print this line‘ • 4 space • Tab • Google use 2 space • We use 4 space (PEP 8)
  • 8. $ vim if_statement.py #!/usr/bin/env python name = raw_input('Please Enter Your name! : ') if name == 'reza': print 'You are reza' print 'And a course instructor' elif name == 'Arman': print 'You are Arman' print 'And a student' else: print 'I don't know you‘ ~ ~ ~
  • 9. $ chmod a+x if_statement.py $ ./if_statement.py Please Enter Your name! : reza You are reza And a course instructor $ $ ./if_statement.py Please Enter Your name! : ali I don’t know you $ $ ./if_statement.py Please Enter Your name! : Arman You are Arman And a student $
  • 10. While Loops while statement_is_true: do stuff do stuff break : get out if innermost loop continue : start the next pass of the innermost pass : do nothing, placeholder
  • 11. $ vim while_statement.py #!/usr/bin/env python age = int(raw_input('Please Enter Your age ? : ')) while age > 10: print 'You age is grater than 10' ~ ~ ~
  • 12. $ chmod a+x while_statement.py $ ./ while_statement.py Please Enter Your age ? : 23 You age is grater than 10 You age is grater than 10 You age is grater than 10 You age is grater than 10 You age is grater than 10 You age is grater than 10 You age is grater than 10 You age is grater than 10 You age is grater than 10 You age is grater than 10 You age is grater than 10 You age is grater than 10 You age is grater than 10 You age is grater than 10 You age is grater than 10 You age is grater than 10
  • 13. $ vim while_statement.py #!/usr/bin/env python age = 20 while age > 10: age = int(raw_input('Please Enter Your age ? : ')) print 'You age is grater than 10' ~ ~ ~
  • 14. $ chmod a+x while_statement.py $ ./ while_statement.py Please Enter Your age ? : 23 You age is grater than 10 Please Enter Your age ? : 15 You age is grater than 10 Please Enter Your age ? : 18 You age is grater than 10 Please Enter Your age ? : 8 You age is grater than 10 $
  • 15. $ vim while_statement.py #!/usr/bin/env python age = 20 while age > 10: age = int(raw_input('Please Enter Your age ? : ')) if age > 10: print 'Your age is grater than 10' elif age < 10: print 'Your age is smaller than 10' else: print 'Your age is equal to 10' ~ ~
  • 16. $ chmod a+x while_statement.py $ ./ while_statement.py Please Enter Your age ? : 23 You age is grater than 10 Please Enter Your age ? : 15 You age is grater than 10 Please Enter Your age ? : 8 You age is smaller than 10 $ $ ./ while_statement.py Please Enter Your age ? : 17 You age is grater than 10 Please Enter Your age ? : 10 You age is equal to 10 $
  • 17. For Loops for item in object: do stuff do stuff for item in [1, 2, 3] for item in ['a', 2, '3'] for (x,y) in [('reza', 23), ('mohammad', 25)]
  • 18. >>> for item in [1, 2, 3]: ... print item ... 1 2 3
  • 19. item is a name can be anything >>> names = ['Reza', 'Majid', 'Sara', 'Iman'] >>> names ['Reza', 'Majid', 'Sara', 'Iman'] >>> for name in names: ... print name ... Reza Majid Sara Iman >>>
  • 20. >>> info = [('Reza', 23), ('Sara', 20), ('Shayan', 30), ('AmirAli', 21)] >>> info [('Reza', 23), ('Sara', 20), ('Shayan', 30), ('AmirAli', 21)] >>> for (name, age) in info: ... print 'Your name is : %s and Your age is %d' % (name, age) ... Your name is : Reza and Your age is 23 Your name is : Sara and Your age is 20 Your name is : Shayan and Your age is 30 Your name is : AmirAli and Your age is 21 >>>
  • 21. Emulating C style for loops C style loops : for(i=0; i<10; i++) for(i=0; i<10; i++){ cout<<i<<','; } 0,1,2,3,4,5,6,7,8,9,
  • 22. range() range(lower, upper, step) create a list for use range(n) – [0,...,n-1] >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>>
  • 23. >>> range(1,10) [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> range(1,10,2) [1, 3, 5, 7, 9] >>> >>> for number in range(1,10,2): ... print number ... 1 3 5 7 9 >>>
  • 24. References • Data model — Python v2.7.5 documentation • http://docs.python.org/2/reference/datamodel.html#objects-values-and-types • PEP 8 -- Style Guide for Python Code • http://www.python.org/dev/peps/pep-0008/ THIS IS A COPYRIGHTED MATERIAL ©2013 Mohammad Reza Kamalifard. ALL RIGHTS RESERVED.