SlideShare a Scribd company logo
‫‪Play with Python‬‬
                          ‫1‪Lab‬‬
‫كل الشرح في المحاضرة، أي مفاهيم في المعامل :قاعدة هامة‬
          ‫ستكون مغطاه في المحاضرة قبل المعمل‬
          ‫المطلوب فقط شرح المطلوب من التمرين‬
                      ‫ودعهم ينطلقون‬
Agenda
•   Setup the Environment and Hello World
•   Exercise 1:
    o   Factorial then Factorial with list
•   Exercise 2:
    o   character count and histogram
•   Fun:
    o   Plot!
Setup the Environment
•   Install Python 2.7.3:
    o   python-2.7.3.msi
•   Install Aptana IDE:
    o   Aptana_Studio_3_Setup_3.2.0.exe
Setup the Environment
  1- Open your Python IDLE from:
  Start >> All Programs >> Python 2.7 >>
IDLE

  2- Write your first program:
  print "Hello World"
  Press Enter
Setup the Environment (Your first project)
3- Start Aptana:
         Start >> All Programs >> Aptana Studio 3
         press ok for the workspace
4- Create your first project:
         Select File >> New >> Project ... >> PyDev Project



5-Enter Project Name: lab1
6-(for first time only) Click on "Please configure an interpreter ... "
7- click auto Config
8- click ok
9- then ok (wait till Aptana finishes ...)
10-create your main file by:
              right click on "lab1" in Package Explorer >> New >> PyDev Module
11- Enter Name: main
12- click ok
Screenshots (steps 3- 12)
Setup the Environment (Your first project)
Write the following code in your main file:
      n = 5
      for i in range(1, n):
       print "Hello World"


click on run as from the toolbar


Select "Python Run "


Click Ok (See the run in Console)
Setup the Environment (Your first project)
put your previous code in a function like this
      def main():
       n = 5
       for i in range(1, n):
          print "Hello World"


   then call it:
   main()
Setup the Environment (Your first project)
again change your main to return 2 values, "hello world"
  string and its length
      def main():
       s = "Hello World"
       return "Hello World", len(s)


   then print the return of main like this:
   print main()
      ('Hello World', 11)
Exercise 1
Write this program in your main file:
def count_char(str):
       d = {}
       for char in str:
              if char in d:
                      d[char] += 1
              else:
                      d[char] = 1
       return d
print count_char("My name is FCIS tell me every thing you know
   !")



{' ': 9, 'C': 1, 'F': 1, 'I': 2, 'M': 1, 'S': 1, 'a': 1, 'e': 5, 'g': 1, 'i': 2, 'h': 1, 'k': 1, 'm': 2, 'l': 2, 'o': 1,
      'n': 3, 's': 1, 'r': 1, 't': 2, 'w': 1, 'v': 1, 'y': 2}
This program counts the occurrences of characters in given string and returns a
    dictionary containing for every key character an integer value
Exercise 1 (10 minutes)
Add a new function draw_historgram() that draws an ascii histogram of a given
   dictionary (from count_char()) like this:
a   :   * *
    :   * * * * * * * * *
e   :   * * * * *
d   :   *
g   :   *
i   :   * *
M   :   *
k   :   *
v   :   *
m   :   * * * *
l   :   * *
o   :   * *
...
Exercise 1 (Solution)
def draw_historgram(d):
    for char in d:
        print char, " : ",
        for c in range(1, d[char]+1):
            print "*",
        print ""
Exercise 2
Write this program in your main file:
def fact(n):
     if (n <= 1):
            return 1
     else:
            return n * fact(n - 1)


print fact(5)
120


this program computes a factorial for a given integer
Exercise 2 (15 minutes)
Modify this function to make it return the factorial, and also
  a list contains all factorials so far like this:


print fact(5)
(120, [1, 2, 6, 24, 120])


the list contains all the factorials from 1 to 5
Exercise 2 (Solution)
def fact(n):
      if (n <= 1):
             return 1, [1]
      else:
             prev_fact, theList = fact(n - 1)


             current_fact = n* prev_fact
             theList.append(current_fact)


             return current_fact, theList



print fact(5)



Note: in this exercise the student should be able to implement the solution with the multiple return values ( tuple), this
    python feature is explained in the lecture
This exercise is to let the students think the in new way of programming, to feel change from C/C++/C3/Java traditional
     languages
Have Fun
Install Pythonxy:
(Click yes for every question the installer asks about
   existing python setup)


Open Spyder by:(Start>>python(x,y) >> Spyder >> Spyder
  )


Copy and paste your Fact() function to the python
  interpreter, and plot Fact() like this:
f, l = fact(5)
plot(l)
Thank You

More Related Content

What's hot

Python Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M25 - os and sys modulesPython Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M25 - os and sys modules
P3 InfoTech Solutions Pvt. Ltd.
 
The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.7 book - Part 30 of 196The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.7 book - Part 30 of 196
Mahmoud Samir Fayed
 
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
Mohammad Reza Kamalifard
 
Functions
FunctionsFunctions
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184
Mahmoud Samir Fayed
 
Java_practical_handbook
Java_practical_handbookJava_practical_handbook
Java_practical_handbook
Manusha Dilan
 
Spock Testing Framework - The Next Generation
Spock Testing Framework - The Next GenerationSpock Testing Framework - The Next Generation
Spock Testing Framework - The Next Generation
BTI360
 
The Ring programming language version 1.5.1 book - Part 32 of 180
The Ring programming language version 1.5.1 book - Part 32 of 180The Ring programming language version 1.5.1 book - Part 32 of 180
The Ring programming language version 1.5.1 book - Part 32 of 180
Mahmoud Samir Fayed
 
kii
kiikii
4. functions
4. functions4. functions
4. functions
PhD Research Scholar
 
Java practical
Java practicalJava practical
Java practical
shweta-sharma99
 
Java simple programs
Java simple programsJava simple programs
Java simple programs
VEERA RAGAVAN
 
Spock Framework - Slidecast
Spock Framework - SlidecastSpock Framework - Slidecast
Spock Framework - Slidecast
Daniel Kolman
 
The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84
Mahmoud Samir Fayed
 
Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...
Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...
Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...
Víctor Bolinches
 
Python Unit Test
Python Unit TestPython Unit Test
Python Unit Test
David Xie
 
Natural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usageNatural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usage
hyunyoung Lee
 
Java 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardJava 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forward
Mario Fusco
 
"PostgreSQL and Python" Lightning Talk @EuroPython2014
"PostgreSQL and Python" Lightning Talk @EuroPython2014"PostgreSQL and Python" Lightning Talk @EuroPython2014
"PostgreSQL and Python" Lightning Talk @EuroPython2014
Henning Jacobs
 

What's hot (19)

Python Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M25 - os and sys modulesPython Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M25 - os and sys modules
 
The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.7 book - Part 30 of 196The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.7 book - Part 30 of 196
 
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
 
Functions
FunctionsFunctions
Functions
 
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184
 
Java_practical_handbook
Java_practical_handbookJava_practical_handbook
Java_practical_handbook
 
Spock Testing Framework - The Next Generation
Spock Testing Framework - The Next GenerationSpock Testing Framework - The Next Generation
Spock Testing Framework - The Next Generation
 
The Ring programming language version 1.5.1 book - Part 32 of 180
The Ring programming language version 1.5.1 book - Part 32 of 180The Ring programming language version 1.5.1 book - Part 32 of 180
The Ring programming language version 1.5.1 book - Part 32 of 180
 
kii
kiikii
kii
 
4. functions
4. functions4. functions
4. functions
 
Java practical
Java practicalJava practical
Java practical
 
Java simple programs
Java simple programsJava simple programs
Java simple programs
 
Spock Framework - Slidecast
Spock Framework - SlidecastSpock Framework - Slidecast
Spock Framework - Slidecast
 
The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84
 
Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...
Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...
Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...
 
Python Unit Test
Python Unit TestPython Unit Test
Python Unit Test
 
Natural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usageNatural language processing open seminar For Tensorflow usage
Natural language processing open seminar For Tensorflow usage
 
Java 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardJava 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forward
 
"PostgreSQL and Python" Lightning Talk @EuroPython2014
"PostgreSQL and Python" Lightning Talk @EuroPython2014"PostgreSQL and Python" Lightning Talk @EuroPython2014
"PostgreSQL and Python" Lightning Talk @EuroPython2014
 

Similar to Python summer course play with python (lab1)

Python program For O level Practical
Python program For O level Practical Python program For O level Practical
Python program For O level Practical
pavitrakumar18
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdf
srxerox
 
Python programming workshop session 4
Python programming workshop session 4Python programming workshop session 4
Python programming workshop session 4
Abdul Haseeb
 
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
Yashpatel821746
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Yashpatel821746
 
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
Yashpatel821746
 
What's new in Python 3.11
What's new in Python 3.11What's new in Python 3.11
What's new in Python 3.11
Henry Schreiner
 
Chapter 02 functions -class xii
Chapter 02   functions -class xiiChapter 02   functions -class xii
Chapter 02 functions -class xii
Praveen M Jigajinni
 
Chapter 1 Class 12 Computer Science Unit 1
Chapter 1 Class 12 Computer Science Unit 1Chapter 1 Class 12 Computer Science Unit 1
Chapter 1 Class 12 Computer Science Unit 1
ssusera7a08a
 
Labsheet_3
Labsheet_3Labsheet_3
Labsheet_3
rohassanie
 
Revision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdfRevision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdf
optimusnotch44
 
Python tour
Python tourPython tour
Python tour
Tamer Abdul-Radi
 
Question 1 briefly respond to all the following questions. make
Question 1 briefly respond to all the following questions. make Question 1 briefly respond to all the following questions. make
Question 1 briefly respond to all the following questions. make
YASHU40
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
CBJWorld
 
The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88
Mahmoud Samir Fayed
 
Functional Programming You Already Know
Functional Programming You Already KnowFunctional Programming You Already Know
Functional Programming You Already Know
Kevlin Henney
 
Basics of MATLAB programming
Basics of MATLAB programmingBasics of MATLAB programming
Basics of MATLAB programming
Ranjan Pal
 
The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181
Mahmoud Samir Fayed
 
C Tutorials
C TutorialsC Tutorials
C Tutorials
Sudharsan S
 
Python Lab manual program for BE First semester (all department
Python Lab manual program for BE First semester (all departmentPython Lab manual program for BE First semester (all department
Python Lab manual program for BE First semester (all department
Nazeer Wahab
 

Similar to Python summer course play with python (lab1) (20)

Python program For O level Practical
Python program For O level Practical Python program For O level Practical
Python program For O level Practical
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdf
 
Python programming workshop session 4
Python programming workshop session 4Python programming workshop session 4
Python programming workshop session 4
 
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
 
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
 
What's new in Python 3.11
What's new in Python 3.11What's new in Python 3.11
What's new in Python 3.11
 
Chapter 02 functions -class xii
Chapter 02   functions -class xiiChapter 02   functions -class xii
Chapter 02 functions -class xii
 
Chapter 1 Class 12 Computer Science Unit 1
Chapter 1 Class 12 Computer Science Unit 1Chapter 1 Class 12 Computer Science Unit 1
Chapter 1 Class 12 Computer Science Unit 1
 
Labsheet_3
Labsheet_3Labsheet_3
Labsheet_3
 
Revision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdfRevision of the basics of python1 (1).pdf
Revision of the basics of python1 (1).pdf
 
Python tour
Python tourPython tour
Python tour
 
Question 1 briefly respond to all the following questions. make
Question 1 briefly respond to all the following questions. make Question 1 briefly respond to all the following questions. make
Question 1 briefly respond to all the following questions. make
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
 
The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88
 
Functional Programming You Already Know
Functional Programming You Already KnowFunctional Programming You Already Know
Functional Programming You Already Know
 
Basics of MATLAB programming
Basics of MATLAB programmingBasics of MATLAB programming
Basics of MATLAB programming
 
The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181
 
C Tutorials
C TutorialsC Tutorials
C Tutorials
 
Python Lab manual program for BE First semester (all department
Python Lab manual program for BE First semester (all departmentPython Lab manual program for BE First semester (all department
Python Lab manual program for BE First semester (all department
 

Recently uploaded

PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Zilliz
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 

Recently uploaded (20)

PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 

Python summer course play with python (lab1)

  • 1. ‫‪Play with Python‬‬ ‫1‪Lab‬‬ ‫كل الشرح في المحاضرة، أي مفاهيم في المعامل :قاعدة هامة‬ ‫ستكون مغطاه في المحاضرة قبل المعمل‬ ‫المطلوب فقط شرح المطلوب من التمرين‬ ‫ودعهم ينطلقون‬
  • 2. Agenda • Setup the Environment and Hello World • Exercise 1: o Factorial then Factorial with list • Exercise 2: o character count and histogram • Fun: o Plot!
  • 3. Setup the Environment • Install Python 2.7.3: o python-2.7.3.msi • Install Aptana IDE: o Aptana_Studio_3_Setup_3.2.0.exe
  • 4. Setup the Environment 1- Open your Python IDLE from: Start >> All Programs >> Python 2.7 >> IDLE 2- Write your first program: print "Hello World" Press Enter
  • 5. Setup the Environment (Your first project) 3- Start Aptana: Start >> All Programs >> Aptana Studio 3 press ok for the workspace 4- Create your first project: Select File >> New >> Project ... >> PyDev Project 5-Enter Project Name: lab1 6-(for first time only) Click on "Please configure an interpreter ... " 7- click auto Config 8- click ok 9- then ok (wait till Aptana finishes ...) 10-create your main file by: right click on "lab1" in Package Explorer >> New >> PyDev Module 11- Enter Name: main 12- click ok
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22. Setup the Environment (Your first project) Write the following code in your main file: n = 5 for i in range(1, n): print "Hello World" click on run as from the toolbar Select "Python Run " Click Ok (See the run in Console)
  • 23. Setup the Environment (Your first project) put your previous code in a function like this def main(): n = 5 for i in range(1, n): print "Hello World" then call it: main()
  • 24. Setup the Environment (Your first project) again change your main to return 2 values, "hello world" string and its length def main(): s = "Hello World" return "Hello World", len(s) then print the return of main like this: print main() ('Hello World', 11)
  • 25. Exercise 1 Write this program in your main file: def count_char(str): d = {} for char in str: if char in d: d[char] += 1 else: d[char] = 1 return d print count_char("My name is FCIS tell me every thing you know !") {' ': 9, 'C': 1, 'F': 1, 'I': 2, 'M': 1, 'S': 1, 'a': 1, 'e': 5, 'g': 1, 'i': 2, 'h': 1, 'k': 1, 'm': 2, 'l': 2, 'o': 1, 'n': 3, 's': 1, 'r': 1, 't': 2, 'w': 1, 'v': 1, 'y': 2} This program counts the occurrences of characters in given string and returns a dictionary containing for every key character an integer value
  • 26. Exercise 1 (10 minutes) Add a new function draw_historgram() that draws an ascii histogram of a given dictionary (from count_char()) like this: a : * * : * * * * * * * * * e : * * * * * d : * g : * i : * * M : * k : * v : * m : * * * * l : * * o : * * ...
  • 27. Exercise 1 (Solution) def draw_historgram(d): for char in d: print char, " : ", for c in range(1, d[char]+1): print "*", print ""
  • 28. Exercise 2 Write this program in your main file: def fact(n): if (n <= 1): return 1 else: return n * fact(n - 1) print fact(5) 120 this program computes a factorial for a given integer
  • 29. Exercise 2 (15 minutes) Modify this function to make it return the factorial, and also a list contains all factorials so far like this: print fact(5) (120, [1, 2, 6, 24, 120]) the list contains all the factorials from 1 to 5
  • 30. Exercise 2 (Solution) def fact(n): if (n <= 1): return 1, [1] else: prev_fact, theList = fact(n - 1) current_fact = n* prev_fact theList.append(current_fact) return current_fact, theList print fact(5) Note: in this exercise the student should be able to implement the solution with the multiple return values ( tuple), this python feature is explained in the lecture This exercise is to let the students think the in new way of programming, to feel change from C/C++/C3/Java traditional languages
  • 31. Have Fun Install Pythonxy: (Click yes for every question the installer asks about existing python setup) Open Spyder by:(Start>>python(x,y) >> Spyder >> Spyder ) Copy and paste your Fact() function to the python interpreter, and plot Fact() like this: f, l = fact(5) plot(l)
  • 32.
  • 33.
  • 34.