SlideShare a Scribd company logo
1 of 6
6.189: Introduction to Programming in Python
Session 1

Course Syllabus
1. Administrivia. Variables and Types.
2. Functions. Basic Recursion.
3. Control Flow: Branching and Repetition.
4. Introduction to Objects: Strings and Lists.
5. Project 1: Structuring Larger Programs.

6. Python Modules. Debugging Programs.
7. Introduction to Data Structures: Dictionaries.
8. Functions as a Type, Anonymous Functions and List Comprehensions
9. Project 2: Working in a Team.
10. Quiz. Wrap-up.

Administrivia
1. Grading. Well, it’s a pass/fail course – attend the classes, do the homework. Attendance is important:
email us in advance if you have to miss a class.

2. Optional Assignment(s). There’s an optional assignment that you can work on when you have free
time, e.g. if you finish the class lab period early. This assignment is completely optional – it was designed
to give you a better intuition for programming and to help in later course 6 studies.


3 . Textbook. This class uses readings from the online textbook How to Think Like a Computer Scientist –
its always nice to have two perspectives on concepts. You can find this textbook at the following link:

              http://www.openbookproject.net/thinkcs/python/english2e/index.xhtml

Notes/Homework
1. Install Python. You can get the latest version at www.python.org.

     ­ Linux and OS X users: You should already have Python installed – to test this, run the command
       python in console mode. Note that the first line tells you the version number: you may want to
       upgrade your installation if you have a version earlier than 2.3.

     ­ Windows users: Grab the windows installer from the Downloads section. After installation, you
       can run the IDLE (Python GUI) command from the Start menu.
2. Reading. Read 1.1-1.2, 1.8-1.9, and chapter 2 from the textbook.

3. Writing Programs. Recall that a program is just a set of instructions for the computer to execute. Let’s
start with a basic command:

print x: Prints the value of the expression x, followed by a newline.

    Program Text:

      print “Hello World!”

      print “How are you?”



    Output:

      Hello World!

      How are you?



(The compiler needs those quotation marks to identify strings – we’ll talk about this later.) Don’t worry,
we’ll be adding many more interesting commands later! For now, though, we’ll use this to have you
become familiar with the administrative details of writing a program.

Write a program that, when run, prints out a tic-tac-toe board.

     ­ Linux and OS X users: To write your program, just create a text file with the contents of the
       program text (e.g. the program text above.) To run your program (pretend its named
       first_print.py), use the command python first_print.py at the shell.

     ­ Windows users: The best way to program in Windows is using the IDLE GUI (from the shortcut
       above.) To create a new program, run the command File->New Window (CTRL+N) – this will open
       up a blank editing window. In general, save your program regularly; after saving, you can hit F5 to
       run your program and see the output.

Make sure to write your program using the computer at least once! The purpose of this question is to
make sure you know how to write programs using your computing environment; many students in
introductory courses experience trouble with assignments not because they have trouble with the
material but because of some weird environment quirk.

You can write the answer to the question in the box below (I know its hard to show spaces while writing
– just do your best)

    Program Text:
Expected Output:

       | |

      -----
       | |

      -----
       | |


4. Interpreter Mode. Python has a write-as-you-go mode that’s useful when testing small snippets of
code. You can access this by running the command python at the shell (for OS X and Linux) or by starting
the IDLE GUI (for Windows) – you should see a >>> prompt. Try typing a print command and watch what
happens.

You’ll find that its much more convenient to solve a lot of the homework problems using the interpreter.
When you want to write an actual, self-contained program (e.g. writing the game tic-tac-toe), follow the
instructions in section 3 above.

5. Variables. Put simply, variables are containers for storing information. For example:

    Program Text:

      a = “Hello World!”
      print a


    Output:

      Hello World!



The = sign is an assignment operator which says: assign the value “Hello World!” to the variable a.

    Program Text:

      a = “Hello World!”
      a = “and goodbye..”
      print a


    Output:

      and goodbye..



Taking this second example, the value of a after executing the first line above is “Hello World!”, and
after the second line its “and goodbye..” (which is what gets printed)
In Python, variables are designed to hold specific types of information. For example, after the first
command above is executed, the variable a is associated with the string type. There are several types of
information that can be stored:

     ­   Boolean. Variables of this type can be either True or False.
     ­   Integer. An integer is a number without a fractional part, e.g. -4, 5, 0, -3.
     ­   Float. Any rational number, e.g. 3.432. We won’t worry about floats for today.
     ­   String. Any sequence of characters. We’ll get more in-depth with strings later in the week.

Python (and many other languages) are zealous about type information. The string “5” and integer 5 are
completely different entities to Python, despite their similar appearance. You’ll see the importance of
this in the next section.

Write a program that stores the value 5 in a variable a and prints out the value of a, then stores the
value 7 in a and prints out the value of a (4 lines.)

    Program Text:




    Expected Output:

      5

      7



6. Operators. Python has the ability to be used as a cheap, 5-dollar calculator. In particular, it supports
basic mathematical operators: +, -, *, /.

    Program Text:

      a = 5 + 7
      print a


    Output:

      12



Variables can be used too.

    Program Text:

      a = 5
      b = a + 7
      print b
Output:

      12



Expressions can get fairly complex.

    Program Text:

      a = (3+4+21) / 7
      b = (9*4) / (2+1) - 6
      print (a*b)-(a+b)

    Output:

      14


These operators work on numbers. Type information is important – the following expressions would
result in an error.

                                  “Hello” / 123       “Hi” + 5      “5” + 7

The last one is especially important! Note that Python just sees that 5 as a string – it has no concept of it
possibly being a number.

Some of the operators that Python includes are

     ­ Addition, Subtraction, Multiplication. a+b, a-b, and a*b respectively.
     ­ Integer Division. a/b. Note that when division is performed with two integers, only the quotient
       is returned (the remainder is ignored.) Try typing print 13/6 into the interpreter
     ­ Exponentiation (ab). a ** b.

Operators are evaluated using the standard order of operations. You can use parentheses to force

certain operators to be evaluated first.


Let’s also introduce one string operation.


     ­ Concatenation. a+b. Combines two strings into one. “Hel” + “lo” would yield “Hello”

Another example of type coming into play! When Python sees a + b, it checks to see what type a and b
are. If they are both strings then it concatenates the two; if they are both integers it adds them; if one is

a string and the other is an integer, it returns an error.


Write the output of the following lines of code (if an error would result, write error):
print 13 + 6                                    Output: _______________________________________
print 2 ** 3                                    Output: _______________________________________
print 2 * (1 + 3)                               Output: _______________________________________
print 8 / 9                                     Output: _______________________________________
print “13” + “6”                                Output: _______________________________________
print “13” + 6                                  Output: _______________________________________

7. Review. Here are the important concepts covered today.

     ­ What is a program? How does one write them.
     ­ Using the interpreter mode.
     ­ Variables: containers for storing information. Variables are typed – each variable only holds
       certain types of data (one might be able to store strings, another might be able to store numbers,
       etc.)
     ­ Operators: +, -, *, /, **, and parentheses.

More Related Content

What's hot

What's hot (20)

AS TASKS #8
AS TASKS #8AS TASKS #8
AS TASKS #8
 
Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)
 
C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1
 
Notes1
Notes1Notes1
Notes1
 
C language
C language C language
C language
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
Mastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_argumentsMastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_arguments
 
Handout#01
Handout#01Handout#01
Handout#01
 
Programming of c++
Programming of c++Programming of c++
Programming of c++
 
C programming language
C programming languageC programming language
C programming language
 
First draft programming c++
First draft programming c++First draft programming c++
First draft programming c++
 
Assignment4
Assignment4Assignment4
Assignment4
 
Structure
StructureStructure
Structure
 
Embedded SW Interview Questions
Embedded SW Interview Questions Embedded SW Interview Questions
Embedded SW Interview Questions
 
Declaration of variables
Declaration of variablesDeclaration of variables
Declaration of variables
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C language
 
Basic Information About C language PDF
Basic Information About C language PDFBasic Information About C language PDF
Basic Information About C language PDF
 
C languaGE UNIT-1
C languaGE UNIT-1C languaGE UNIT-1
C languaGE UNIT-1
 
Chapter3
Chapter3Chapter3
Chapter3
 

Viewers also liked

1000 keek followers free
1000 keek followers free1000 keek followers free
1000 keek followers freekelly895
 
Whitney - Comm Law Paper
Whitney - Comm Law PaperWhitney - Comm Law Paper
Whitney - Comm Law PaperWhitney Yount
 
Innovation for SME Businesses- Fasttrack for Innovation - Horizon 2020 Funding
Innovation for SME Businesses- Fasttrack for Innovation - Horizon 2020 FundingInnovation for SME Businesses- Fasttrack for Innovation - Horizon 2020 Funding
Innovation for SME Businesses- Fasttrack for Innovation - Horizon 2020 FundingThe Pathway Group
 
10 la palabra y la oracion
10 la palabra y la oracion10 la palabra y la oracion
10 la palabra y la oracionchucho1943
 
Methods of Documentation RSC Final Report
Methods of Documentation RSC Final ReportMethods of Documentation RSC Final Report
Methods of Documentation RSC Final ReportNatalie Yunxian
 
Publisher
PublisherPublisher
Publisherjonxket
 
Cary Nadler, Phd.
Cary Nadler, Phd.Cary Nadler, Phd.
Cary Nadler, Phd.rearden638
 
Презентация на тему: «Административные барьеры в процессах международной торг...
Презентация на тему: «Административные барьеры в процессах международной торг...Презентация на тему: «Административные барьеры в процессах международной торг...
Презентация на тему: «Административные барьеры в процессах международной торг...НЭПК "СОЮЗ "АТАМЕКЕН"
 
Shamit khemka list outs 6 technology trends for 2015
Shamit khemka list outs 6 technology trends for 2015Shamit khemka list outs 6 technology trends for 2015
Shamit khemka list outs 6 technology trends for 2015SynapseIndia
 
3430_3440Brochure_Final_PRINT
3430_3440Brochure_Final_PRINT3430_3440Brochure_Final_PRINT
3430_3440Brochure_Final_PRINTNeil Hunt
 

Viewers also liked (17)

Presentación2
Presentación2Presentación2
Presentación2
 
Smm project 1
Smm project 1Smm project 1
Smm project 1
 
Trabajo de lengua siglo xviii
Trabajo de lengua siglo xviiiTrabajo de lengua siglo xviii
Trabajo de lengua siglo xviii
 
Qosmet 20160219
Qosmet 20160219Qosmet 20160219
Qosmet 20160219
 
1000 keek followers free
1000 keek followers free1000 keek followers free
1000 keek followers free
 
Tusc movie
Tusc movieTusc movie
Tusc movie
 
Whitney - Comm Law Paper
Whitney - Comm Law PaperWhitney - Comm Law Paper
Whitney - Comm Law Paper
 
Management Quiz
Management QuizManagement Quiz
Management Quiz
 
Innovation for SME Businesses- Fasttrack for Innovation - Horizon 2020 Funding
Innovation for SME Businesses- Fasttrack for Innovation - Horizon 2020 FundingInnovation for SME Businesses- Fasttrack for Innovation - Horizon 2020 Funding
Innovation for SME Businesses- Fasttrack for Innovation - Horizon 2020 Funding
 
Punim seminarik
Punim seminarikPunim seminarik
Punim seminarik
 
10 la palabra y la oracion
10 la palabra y la oracion10 la palabra y la oracion
10 la palabra y la oracion
 
Methods of Documentation RSC Final Report
Methods of Documentation RSC Final ReportMethods of Documentation RSC Final Report
Methods of Documentation RSC Final Report
 
Publisher
PublisherPublisher
Publisher
 
Cary Nadler, Phd.
Cary Nadler, Phd.Cary Nadler, Phd.
Cary Nadler, Phd.
 
Презентация на тему: «Административные барьеры в процессах международной торг...
Презентация на тему: «Административные барьеры в процессах международной торг...Презентация на тему: «Административные барьеры в процессах международной торг...
Презентация на тему: «Административные барьеры в процессах международной торг...
 
Shamit khemka list outs 6 technology trends for 2015
Shamit khemka list outs 6 technology trends for 2015Shamit khemka list outs 6 technology trends for 2015
Shamit khemka list outs 6 technology trends for 2015
 
3430_3440Brochure_Final_PRINT
3430_3440Brochure_Final_PRINT3430_3440Brochure_Final_PRINT
3430_3440Brochure_Final_PRINT
 

Similar to pyton Notes1

Python for Physical Science.pdf
Python for Physical Science.pdfPython for Physical Science.pdf
Python for Physical Science.pdfMarilouANDERSON
 
python introduction initial lecture unit1.pptx
python introduction initial lecture unit1.pptxpython introduction initial lecture unit1.pptx
python introduction initial lecture unit1.pptxChandraPrakash715640
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonmckennadglyn
 
PYTHON NOTES
PYTHON NOTESPYTHON NOTES
PYTHON NOTESNi
 
Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++KurdGul
 
pythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxpythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxRohitKumar639388
 
Fundamentals of python
Fundamentals of pythonFundamentals of python
Fundamentals of pythonBijuAugustian
 
C++ In One Day_Nho Vĩnh Share
C++ In One Day_Nho Vĩnh ShareC++ In One Day_Nho Vĩnh Share
C++ In One Day_Nho Vĩnh ShareNho Vĩnh
 
BASIC_INTRODUCTION_TO_PYTHON_PROGRAMMING.pdf
BASIC_INTRODUCTION_TO_PYTHON_PROGRAMMING.pdfBASIC_INTRODUCTION_TO_PYTHON_PROGRAMMING.pdf
BASIC_INTRODUCTION_TO_PYTHON_PROGRAMMING.pdfashaks17
 
265 ge8151 problem solving and python programming - 2 marks with answers
265   ge8151 problem solving and python programming - 2 marks with answers265   ge8151 problem solving and python programming - 2 marks with answers
265 ge8151 problem solving and python programming - 2 marks with answersvithyanila
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonRanjith kumar
 
Python Programming - II. The Basics
Python Programming - II. The BasicsPython Programming - II. The Basics
Python Programming - II. The BasicsRanel Padon
 
Python Introduction Week-1 Term-3.pptx
Python Introduction Week-1 Term-3.pptxPython Introduction Week-1 Term-3.pptx
Python Introduction Week-1 Term-3.pptxMohammad300758
 

Similar to pyton Notes1 (20)

Python for Physical Science.pdf
Python for Physical Science.pdfPython for Physical Science.pdf
Python for Physical Science.pdf
 
Python fundamentals
Python fundamentalsPython fundamentals
Python fundamentals
 
python introduction initial lecture unit1.pptx
python introduction initial lecture unit1.pptxpython introduction initial lecture unit1.pptx
python introduction initial lecture unit1.pptx
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python basics
Python basicsPython basics
Python basics
 
Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++
 
PYTHON NOTES
PYTHON NOTESPYTHON NOTES
PYTHON NOTES
 
Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++
 
Spsl iv unit final
Spsl iv unit  finalSpsl iv unit  final
Spsl iv unit final
 
Spsl iv unit final
Spsl iv unit  finalSpsl iv unit  final
Spsl iv unit final
 
Python training
Python trainingPython training
Python training
 
pythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptxpythontraining-201jn026043638.pptx
pythontraining-201jn026043638.pptx
 
Fundamentals of python
Fundamentals of pythonFundamentals of python
Fundamentals of python
 
C++ In One Day_Nho Vĩnh Share
C++ In One Day_Nho Vĩnh ShareC++ In One Day_Nho Vĩnh Share
C++ In One Day_Nho Vĩnh Share
 
BASIC_INTRODUCTION_TO_PYTHON_PROGRAMMING.pdf
BASIC_INTRODUCTION_TO_PYTHON_PROGRAMMING.pdfBASIC_INTRODUCTION_TO_PYTHON_PROGRAMMING.pdf
BASIC_INTRODUCTION_TO_PYTHON_PROGRAMMING.pdf
 
265 ge8151 problem solving and python programming - 2 marks with answers
265   ge8151 problem solving and python programming - 2 marks with answers265   ge8151 problem solving and python programming - 2 marks with answers
265 ge8151 problem solving and python programming - 2 marks with answers
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
The basics of c programming
The basics of c programmingThe basics of c programming
The basics of c programming
 
Python Programming - II. The Basics
Python Programming - II. The BasicsPython Programming - II. The Basics
Python Programming - II. The Basics
 
Python Introduction Week-1 Term-3.pptx
Python Introduction Week-1 Term-3.pptxPython Introduction Week-1 Term-3.pptx
Python Introduction Week-1 Term-3.pptx
 

More from Amba Research (20)

Case Econ08 Ppt 16
Case Econ08 Ppt 16Case Econ08 Ppt 16
Case Econ08 Ppt 16
 
Case Econ08 Ppt 08
Case Econ08 Ppt 08Case Econ08 Ppt 08
Case Econ08 Ppt 08
 
Case Econ08 Ppt 11
Case Econ08 Ppt 11Case Econ08 Ppt 11
Case Econ08 Ppt 11
 
Case Econ08 Ppt 14
Case Econ08 Ppt 14Case Econ08 Ppt 14
Case Econ08 Ppt 14
 
Case Econ08 Ppt 12
Case Econ08 Ppt 12Case Econ08 Ppt 12
Case Econ08 Ppt 12
 
Case Econ08 Ppt 10
Case Econ08 Ppt 10Case Econ08 Ppt 10
Case Econ08 Ppt 10
 
Case Econ08 Ppt 15
Case Econ08 Ppt 15Case Econ08 Ppt 15
Case Econ08 Ppt 15
 
Case Econ08 Ppt 13
Case Econ08 Ppt 13Case Econ08 Ppt 13
Case Econ08 Ppt 13
 
Case Econ08 Ppt 07
Case Econ08 Ppt 07Case Econ08 Ppt 07
Case Econ08 Ppt 07
 
Case Econ08 Ppt 06
Case Econ08 Ppt 06Case Econ08 Ppt 06
Case Econ08 Ppt 06
 
Case Econ08 Ppt 05
Case Econ08 Ppt 05Case Econ08 Ppt 05
Case Econ08 Ppt 05
 
Case Econ08 Ppt 04
Case Econ08 Ppt 04Case Econ08 Ppt 04
Case Econ08 Ppt 04
 
Case Econ08 Ppt 03
Case Econ08 Ppt 03Case Econ08 Ppt 03
Case Econ08 Ppt 03
 
Case Econ08 Ppt 02
Case Econ08 Ppt 02Case Econ08 Ppt 02
Case Econ08 Ppt 02
 
Case Econ08 Ppt 01
Case Econ08 Ppt 01Case Econ08 Ppt 01
Case Econ08 Ppt 01
 
pyton Notes9
pyton Notes9pyton Notes9
pyton Notes9
 
Notes8
Notes8Notes8
Notes8
 
Notes7
Notes7Notes7
Notes7
 
pyton Notes6
 pyton Notes6 pyton Notes6
pyton Notes6
 
pyton Exam1 soln
 pyton Exam1 soln pyton Exam1 soln
pyton Exam1 soln
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 

Recently uploaded (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 

pyton Notes1

  • 1. 6.189: Introduction to Programming in Python Session 1 Course Syllabus 1. Administrivia. Variables and Types. 2. Functions. Basic Recursion. 3. Control Flow: Branching and Repetition. 4. Introduction to Objects: Strings and Lists. 5. Project 1: Structuring Larger Programs. 6. Python Modules. Debugging Programs. 7. Introduction to Data Structures: Dictionaries. 8. Functions as a Type, Anonymous Functions and List Comprehensions 9. Project 2: Working in a Team. 10. Quiz. Wrap-up. Administrivia 1. Grading. Well, it’s a pass/fail course – attend the classes, do the homework. Attendance is important: email us in advance if you have to miss a class. 2. Optional Assignment(s). There’s an optional assignment that you can work on when you have free time, e.g. if you finish the class lab period early. This assignment is completely optional – it was designed to give you a better intuition for programming and to help in later course 6 studies. 3 . Textbook. This class uses readings from the online textbook How to Think Like a Computer Scientist – its always nice to have two perspectives on concepts. You can find this textbook at the following link: http://www.openbookproject.net/thinkcs/python/english2e/index.xhtml Notes/Homework 1. Install Python. You can get the latest version at www.python.org. ­ Linux and OS X users: You should already have Python installed – to test this, run the command python in console mode. Note that the first line tells you the version number: you may want to upgrade your installation if you have a version earlier than 2.3. ­ Windows users: Grab the windows installer from the Downloads section. After installation, you can run the IDLE (Python GUI) command from the Start menu.
  • 2. 2. Reading. Read 1.1-1.2, 1.8-1.9, and chapter 2 from the textbook. 3. Writing Programs. Recall that a program is just a set of instructions for the computer to execute. Let’s start with a basic command: print x: Prints the value of the expression x, followed by a newline. Program Text: print “Hello World!” print “How are you?” Output: Hello World! How are you? (The compiler needs those quotation marks to identify strings – we’ll talk about this later.) Don’t worry, we’ll be adding many more interesting commands later! For now, though, we’ll use this to have you become familiar with the administrative details of writing a program. Write a program that, when run, prints out a tic-tac-toe board. ­ Linux and OS X users: To write your program, just create a text file with the contents of the program text (e.g. the program text above.) To run your program (pretend its named first_print.py), use the command python first_print.py at the shell. ­ Windows users: The best way to program in Windows is using the IDLE GUI (from the shortcut above.) To create a new program, run the command File->New Window (CTRL+N) – this will open up a blank editing window. In general, save your program regularly; after saving, you can hit F5 to run your program and see the output. Make sure to write your program using the computer at least once! The purpose of this question is to make sure you know how to write programs using your computing environment; many students in introductory courses experience trouble with assignments not because they have trouble with the material but because of some weird environment quirk. You can write the answer to the question in the box below (I know its hard to show spaces while writing – just do your best) Program Text:
  • 3. Expected Output: | | ----- | | ----- | | 4. Interpreter Mode. Python has a write-as-you-go mode that’s useful when testing small snippets of code. You can access this by running the command python at the shell (for OS X and Linux) or by starting the IDLE GUI (for Windows) – you should see a >>> prompt. Try typing a print command and watch what happens. You’ll find that its much more convenient to solve a lot of the homework problems using the interpreter. When you want to write an actual, self-contained program (e.g. writing the game tic-tac-toe), follow the instructions in section 3 above. 5. Variables. Put simply, variables are containers for storing information. For example: Program Text: a = “Hello World!” print a Output: Hello World! The = sign is an assignment operator which says: assign the value “Hello World!” to the variable a. Program Text: a = “Hello World!” a = “and goodbye..” print a Output: and goodbye.. Taking this second example, the value of a after executing the first line above is “Hello World!”, and after the second line its “and goodbye..” (which is what gets printed)
  • 4. In Python, variables are designed to hold specific types of information. For example, after the first command above is executed, the variable a is associated with the string type. There are several types of information that can be stored: ­ Boolean. Variables of this type can be either True or False. ­ Integer. An integer is a number without a fractional part, e.g. -4, 5, 0, -3. ­ Float. Any rational number, e.g. 3.432. We won’t worry about floats for today. ­ String. Any sequence of characters. We’ll get more in-depth with strings later in the week. Python (and many other languages) are zealous about type information. The string “5” and integer 5 are completely different entities to Python, despite their similar appearance. You’ll see the importance of this in the next section. Write a program that stores the value 5 in a variable a and prints out the value of a, then stores the value 7 in a and prints out the value of a (4 lines.) Program Text: Expected Output: 5 7 6. Operators. Python has the ability to be used as a cheap, 5-dollar calculator. In particular, it supports basic mathematical operators: +, -, *, /. Program Text: a = 5 + 7 print a Output: 12 Variables can be used too. Program Text: a = 5 b = a + 7 print b
  • 5. Output: 12 Expressions can get fairly complex. Program Text: a = (3+4+21) / 7 b = (9*4) / (2+1) - 6 print (a*b)-(a+b) Output: 14 These operators work on numbers. Type information is important – the following expressions would result in an error. “Hello” / 123 “Hi” + 5 “5” + 7 The last one is especially important! Note that Python just sees that 5 as a string – it has no concept of it possibly being a number. Some of the operators that Python includes are ­ Addition, Subtraction, Multiplication. a+b, a-b, and a*b respectively. ­ Integer Division. a/b. Note that when division is performed with two integers, only the quotient is returned (the remainder is ignored.) Try typing print 13/6 into the interpreter ­ Exponentiation (ab). a ** b. Operators are evaluated using the standard order of operations. You can use parentheses to force certain operators to be evaluated first. Let’s also introduce one string operation. ­ Concatenation. a+b. Combines two strings into one. “Hel” + “lo” would yield “Hello” Another example of type coming into play! When Python sees a + b, it checks to see what type a and b are. If they are both strings then it concatenates the two; if they are both integers it adds them; if one is a string and the other is an integer, it returns an error. Write the output of the following lines of code (if an error would result, write error):
  • 6. print 13 + 6 Output: _______________________________________ print 2 ** 3 Output: _______________________________________ print 2 * (1 + 3) Output: _______________________________________ print 8 / 9 Output: _______________________________________ print “13” + “6” Output: _______________________________________ print “13” + 6 Output: _______________________________________ 7. Review. Here are the important concepts covered today. ­ What is a program? How does one write them. ­ Using the interpreter mode. ­ Variables: containers for storing information. Variables are typed – each variable only holds certain types of data (one might be able to store strings, another might be able to store numbers, etc.) ­ Operators: +, -, *, /, **, and parentheses.