DEMONSTRATE-MIT Introduction to Computer Science and Programming in Python 6.0001 Fall 2016 Undergraduate

From CompleteNoobs
Revision as of 18:32, 3 December 2023 by Noob (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Please Select a Licence from the LICENCE_HEADERS page
And place at top of your page
If no Licence is Selected/Appended, Default will be CC0

Default Licence IF there is no Licence placed below this notice! When you edit this page, you agree to release your contribution under the CC0 Licence

LICENCE: More information about the cc0 licence can be found here:
https://creativecommons.org/share-your-work/public-domain/cc0

The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law.

You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

Licence:

Statement of Purpose

The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").

Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.

For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.

1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:

   the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
   moral rights retained by the original author(s) and/or performer(s);
   publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
   rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
   rights protecting the extraction, dissemination, use and reuse of data in a Work;
   database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
   other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.

2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.

3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.

4. Limitations and Disclaimers.

   No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
   Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
   Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
   Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.

LICENCE: When you edit this page, you agree to release your contribution under the CC BY-NC-SA Licence
More information about the CC BY-NC-SA licence can be found here:
https://creativecommons.org/licenses/by-nc-sa/4.0/

Over View

You are free to:

    Share — copy and redistribute the material in any medium or format
    Adapt — remix, transform, and build upon the material 



    Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.

    NonCommercial — You may not use the material for commercial purposes.

    ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.

    No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.

Licence:

Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License

By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions.

Section 1 – Definitions.

    Adapted Material means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image.
    Adapter's License means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License.
    BY-NC-SA Compatible License means a license listed at creativecommons.org/compatiblelicenses, approved by Creative Commons as essentially the equivalent of this Public License.
    Copyright and Similar Rights means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights.
    Effective Technological Measures means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements.
    Exceptions and Limitations means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material.
    License Elements means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution, NonCommercial, and ShareAlike.
    Licensed Material means the artistic or literary work, database, or other material to which the Licensor applied this Public License.
    Licensed Rights means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license.
    Licensor means the individual(s) or entity(ies) granting rights under this Public License.
    NonCommercial means not primarily intended for or directed towards commercial advantage or monetary compensation. For purposes of this Public License, the exchange of the Licensed Material for other material subject to Copyright and Similar Rights by digital file-sharing or similar means is NonCommercial provided there is no payment of monetary compensation in connection with the exchange.
    Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them.
    Sui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world.
    You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning.

Section 2 – Scope.

    License grant.
        Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to:
            reproduce and Share the Licensed Material, in whole or in part, for NonCommercial purposes only; and
            produce, reproduce, and Share Adapted Material for NonCommercial purposes only.
        Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions.
        Term. The term of this Public License is specified in Section 6(a).
        Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material.
        Downstream recipients.
            Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License.
            Additional offer from the Licensor – Adapted Material. Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply.
            No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material.
        No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i).

    Other rights.
        Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise.
        Patent and trademark rights are not licensed under this Public License.
        To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for NonCommercial purposes.

Section 3 – License Conditions.

Your exercise of the Licensed Rights is expressly made subject to the following conditions.

    Attribution.

        If You Share the Licensed Material (including in modified form), You must:
            retain the following if it is supplied by the Licensor with the Licensed Material:
                identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated);
                a copyright notice;
                a notice that refers to this Public License;
                a notice that refers to the disclaimer of warranties;
                a URI or hyperlink to the Licensed Material to the extent reasonably practicable;
            indicate if You modified the Licensed Material and retain an indication of any previous modifications; and
            indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License.
        You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information.
        If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable.
    ShareAlike.

    In addition to the conditions in Section 3(a), if You Share Adapted Material You produce, the following conditions also apply.
        The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-NC-SA Compatible License.
        You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material.
        You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply.

Section 4 – Sui Generis Database Rights.

Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material:

    for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database for NonCommercial purposes only;
    if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section 3(b); and
    You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database.

For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights.

Section 5 – Disclaimer of Warranties and Limitation of Liability.

    Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.
    To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.

    The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability.

Section 6 – Term and Termination.

    This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically.

    Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates:
        automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or
        upon express reinstatement by the Licensor.
    For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License.
    For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License.
    Sections 1, 5, 6, 7, and 8 survive termination of this Public License.

Section 7 – Other Terms and Conditions.

    The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed.
    Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License.

Section 8 – Interpretation.

    For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License.
    To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions.
    No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor.
    Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority.


NOTE: This page is for demonstration purposes Only, and is not meant to be hosted on CompleteNoobs.com which is not intended to contain CC_BY-NC-SA Licensed Content.
This page is CC_BY-NC-SA It is intended for a fork of "CompleteNoobs.com" called "CompleteNoobz.com"
CompleteNoobz.com is a noncommercial mirror of CompleteNoobs.com Which can pullin CC_BY-NC-SA Licensed Content
This page is quickly put together to test and demonstrate hosting heavy data content on IPFS.
It is a first draft (UNFINISHED) and required many more Reiterations, This content is first draft concept demonstration content.


Course Information

Source

https://ocw.mit.edu/MIT OPEN COURSEWARE - MASSACHUSETTS INSTITUTE OF TECHNOLOGY.
Donations to support MIT Open Courseware https://giving.mit.edu/give/to/ocw/

https://ocw.mit.edu/courses/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/download/
https://ocw.mit.edu/courses/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/pages/assignments/
https://ocw.mit.edu/courses/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/resources/lecture-videos/

Syllabus

Syllabus

Course Meeting Times

Lectures: 2 sessions / week, 1 hour / session

Recitations: 1 sessions / week, 1 hour / session

Course Information

6.0001 Introduction to Computer Science and Programming in Python is intended for students with little or no programming experience. It aims to provide students with an understanding of the role computation can play in solving problems and to help students, regardless of their major, feel justifiably confident of their ability to write small programs that allow them to accomplish useful goals. The class will use the Python 3.5 programming language.

This is a half-semester course. Students who successfully complete 6.0001 may continue into 6.0002 Introduction to Computational Thinking and Data Science, which is taught in the second half of the semester.

Goals

  • Provide an understanding of the role computation can play in solving problems.
  • Help students, including those who do not plan to major in Computer Science and Electrical Engineering, feel confident of their ability to write small programs that allow them to accomplish useful goals.
  • Position students so that they can compete for research projects and excel in subjects with programming components.

Textbook

The textbook is Buy at MIT Press Guttag, John. Introduction to Computation and Programming Using Python: With Application to Understanding Data Second Edition. MIT Press, 2016. ISBN: 9780262529624. The book and the course lectures parallel each other, though there is more detail in the book about some topics. It is available both in hard copy and as an e-book.

Lecture and Recitation Attendance

A significant portion of the material for this course will presented only in lecture, so students are expected to regularly attend lectures.

Recitations give students a chance to ask questions about the lecture material or the problem set for the given week. Sometimes, new material may be covered in recitation. Recitation attendance is encouraged but not required.

Problem Sets and Quizzes

Each problem set will involve programming in Python. There will be 6 problem sets in the course. There will be two quizzes. All quizzes will be closed-book, though you will be allowed to bring one page of notes to the first quiz and two pages of notes to the second quiz. Pages must be letter-sized, double-sided, either handwritten or typed.

Grading Policy

Grades will be roughly computed as follows:
ACTIVITIES PERCENTAGES
Problem sets 30%
Completion of mandatory finger exercises 10%
Midterm Quiz 20%
Final Quiz 40%


Problem sets will be graded out of 10 points. Submissions that do not run will receive at most 20% of the points. Please contact your Teaching Assistant if you have a problem understanding your problem set grade.

Note: Quizzes and finger exercises are not available on OpenCourseWare.


Extension and Dropping Problem Sets Policy

We do not grant any extensions. Instead, we offer late days and the option of rolling at most 2 problem set grades into the final quiz score.

Late Days

At the beginning of the term, students are given two late days that they can use on problem sets. Starting with Problem Set 1, additional late days can be accumulated for each assignment, one late day for each day the assignment is turned in ahead of the deadline. Up to three late days may be accumulated in this fashion in this course, i.e you can only have a maximum of 3 late days at any point in time. Late days are discrete (a student cannot use half a late day). The staff will keep track of late days and feedback for each problem set will include the number of late days the student has remaining. Any additional late work beyond these late days will not be accepted. To avoid surprises, we suggest that after you submit your problem set, you double check to make sure the submission was uploaded correctly.

Rolling Over Problem Sets

Before the final quiz, we will send out an announcement in which you can choose at most 2 problem sets that you can drop. If dropped, the percent that the problem sets are worth will be rolled into the final quiz score. We strongly urge you to see the late days and dropping the problem sets as backup in case of an emergency. Your best strategy is to do the problem sets early before work starts to pile up.

Calendar

Calendar
SES # TOPICS ASSIGNMENTS
1 What is computation? Pset 0 released
2 Branching and Iteration Pset 1 released
3 String Manipulation, Guess and Check, Approximations, Bisection Pset 0 due
4 Decomposition, Abstractions, Functions Pset 2 released
5 Tuples, Lists, Aliasing, Mutability, Cloning Pset 1 due
6 Recursion, Dictionaries Pset 3 released
7 Testing, Debugging, Exceptions, Assertions Pset 2 due; Quiz 1
8 Object Oriented Programming
9 Python Classes and Inheritance Pset 3 due; Pset 4 released
10 Understanding Program Efficiency, Part 1 Pset 4 due; Pset 5 released
11 Understanding Program Efficiency, Part 2
12 Searching and Sorting Pset 5 due; Final Quiz

Course Materials

Downloading Using IPFS

https://github.com/ipfs/ipfs-desktop/releases
PFS Basics

Software

This class is using python3 IDE spyder which is in Anaconda3
https://www.anaconda.com/
How to install is on Problem Set 0

MIT6_0001F16_Style Guide

Source:https://ocw.mit.edu/courses/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/resources/mit6_0001f16_styleguide/
IPFS:QmUmtyNpSLr2fXwGY1gL2hNnpwbYe8Y7CP2rPwjSNXasxJ

Problem Set 0

Source:https://ocw.mit.edu/courses/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/resources/ps0/
IPFS:QmRWpBvwUNiFRjSvgLjRoiCNXQBBL2aLg55PVfGWw7S1ns

Lecture 1: What is Computation?


Source:https://ocw.mit.edu/courses/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/resources/lecture-1-what-is-computation/
IPFS:QmaTdTMxWdz6ySLbx258zQU5McpJTo4ZEVJ63GSKmVEyeM

Glossary

Glossary for lecture with timestamps:

Time: data
2:10 pset = problem set
12:18 Square_root

Video transcript

Video transcript

The following content is provided under a Creative
0:03Commons license.
0:04Your support will help MIT OpenCourseWare
0:07continue to offer high-quality, educational resources for free.
0:11To make a donation, or view additional materials
0:13from hundreds of MIT courses, visit MIT OpenCourseWare
0:17at ocw.mit.edu.
0:29ANA BELL: All right.
0:30Let's begin.
0:33As I mentioned before, this lecture
0:35will be recorded for OCW.
0:37Again, in future lectures, if you
0:39don't want to have the back of your head show up,
0:41just don't sit in this front area here.
0:44First of all, wow, what a crowd, you guys.
0:46We're finally in 26-100.
0:486.0001 made it big, huh?
0:52Good afternoon and welcome to the very first class of 6.0001,
0:55and also 600, this semester.
0:58My name is Ana Bell.
1:00First name, Ana.
1:01Last name, Bell.
1:03I'm a lecturer in the EECS Department.
1:06And I'll be giving some of the lectures for today,
1:08along with later on in the term, Professor Eric Grimson, who's
1:13sitting right down there, will be giving some of the lectures,
1:15as well.
1:17Today we're going to go over some basic administrivia,
1:21a little bit of course information.
1:23And then, we're going to talk a little bit
1:24about what is computation?
1:26We'll discuss at a very high level
1:27what computers do just to make sure we're all
1:29on the same page.
1:31And then, we're going to dive right into Python basics.
1:34We're going to talk a little bit about mathematical operations
1:36you can do with Python.
1:38And then, we're going to talk about Python variables
1:40and types.
1:42As I mentioned in my introductory email, all
1:43the slides and code that I'll talk about during lectures
1:46will be up before lecture, so I highly
1:48encourage you to download them and to have them open.
1:52We're going to go through some in-class exercises which will
1:56be available on those slides.
1:57And it's fun to do.
1:59And it's also great if could take notes about the code just
2:07for future reference.
2:09It's true.
2:10This is a really fast-paced course,
2:12and we ramp up really quickly.
2:14We do want to position you to succeed in this course.
2:17As I was writing this, I was trying
2:19to think about when I was first starting
2:21to program what helped me get through my very
2:24first programming course.
2:26And this is really a good list.
2:29The first thing was I just read the psets as soon
2:31as they came out, made sure that the terminology just sunk in.
2:37And then, during lectures, if the lecturer
2:39was talking about something that suddenly I remembered,
2:42oh, I saw that word in the pset and I didn't know what it was.
2:45Well, hey, now I know what it is.
2:46Right?
2:47So just give it a read.
2:48You don't need to start it.
2:51If you're new to programming, I think the key word is practice.
2:55It's like math or reading.
2:57The more you practice, the better you get at it.
3:00You're not going to absorb programming
3:01by watching me write programs because I already know how
3:04to program.
3:05You guys need to practice.
3:07Download the code before lecture.
3:09Follow along.
3:10Whatever I type, you guys can type.
3:12And I think, also, one of the big things
3:14is if you're new to programming, you're
3:16kind of afraid that you're going to break your computer.
3:19And you can't really do that just by running Anaconda
3:24and typing in some commands.
3:26So don't be afraid to just type some stuff in
3:28and see what it does.
3:29Worst case, you just restart the computer.
3:35Yeah.
3:36That's probably the big thing right there.
3:38I should have probably highlighted it,
3:39but don't be afraid.
3:40Great.
3:41So this is pretty much a roadmap of all of 6.0001 or 600
3:46as I've just explained it.
3:47There's three big things we want to get out of this course.
3:51The first thing is the knowledge of concepts,
3:54which is pretty much true of any class that you'll take.
3:56The class will teach you something through lectures.
3:59Exams will test how much you know.
4:02This is a class in programming.
4:05The other thing we want you to get out of it
4:08is programming skills.
4:10And the last thing, and I think this
4:12is what makes this class really great,
4:13is we teach you how to solve problems.
4:16And we do that through the psets.
4:18That's really how I feel the roadmap of this course
4:21looks like.
4:22And underlying all of these is just practice.
4:25You have to just type some stuff away and code a lot.
4:29And you'll succeed in this course, I think.
4:33OK.
4:35So what are the things we're going to learn in this class?
4:38I feel like the things we're going learn in this class
4:41can be divided into basically three different sections.
4:44The first one is related to these first two items here.
4:50It's really about learning how to program.
4:53Learning how to program, part of it
4:55is figuring out what objects to create.
4:58You'll learn about these later.
5:00How do you represent knowledge with data structures?
5:02That's sort of the broad term for that.
5:04And then, as you're writing programs,
5:06you need to-- programs aren't just linear.
5:08Sometimes programs jump around.
5:10They make decisions.
5:11There's some control flow to programs.
5:13That's what the second line is going to be about.
5:18The second big part of this course
5:20is a little bit more abstract, and it
5:24deals with how do you write good code, good style,
5:29code that's readable.
5:30When you write code, you want to write it such
5:33that-- you're in big company, other people will read it,
5:35other people will use it, so it has
5:37to be readable and understandable by others.
5:40To that end, you need to write code
5:41that's well organized, modular, easy to understand.
5:48And not only that, not only will your code
5:50be read by other people, but next year, maybe,
5:53you'll take another course, and you'll
5:55want to look back at some of the problems
5:56that you wrote in this class.
5:58You want to be able to reread your code.
6:00If it's a big mess, you might not be able to understand--
6:03or reunderstand-- what you were doing.
6:06So writing readable code and organizing code
6:08is also a big part.
6:10And the last section is going to deal with-- the first two
6:15are actually part of the programming in Introduction
6:19to Programming and Computer Science in Python.
6:21And the last one deals mostly with the computer science part
6:26in Introduction to Programming and Computer Science in Python.
6:29We're going to talk about, once you have learned
6:31how to write programs in Python, how do
6:33you compare programs in Python?
6:35How do you know that one program is better than the other?
6:38How do you know that one program is
6:39more efficient than the other?
6:41How do you know that one algorithm
6:42is better than the other?
6:45That's what we're going to talk about in the last part
6:47of the course.
6:48OK.
6:50That's all for the administrative part
6:52of the course.
6:54Let's start by talking at a high level what does a computer do.
6:59Fundamentally, it does two things.
7:03One, performs calculations.
7:05It performs a lot of calculations.
7:07Computers these days are really, really fast,
7:09a billion calculations per second is probably not far off.
7:15It performs these calculations and it
7:16has to store them somewhere.
7:18Right?
7:19Stores them in computer memory.
7:21So a computer also has to remember results.
7:24And these days, it's not uncommon to find computers
7:26with hundreds of gigabytes of storage.
7:30The kinds of calculations that computers do,
7:34there are two kinds.
7:35One are calculations that are built into the language.
7:37These are the very low level types
7:39of calculations, things like addition,
7:41subtraction, multiplication, and so on.
7:45And once you have a language that
7:47has these primitive calculation types, you, as a programmer,
7:53can put these types together and then define
7:55your own calculations.
7:57You can create new types of calculations.
8:00And the computer will be able to perform those, as well.
8:04I think, one thing I want to stress--
8:07and we're going to come back to this
8:09again during this entire lecture, actually--
8:12is computers only know what you tell them.
8:15Computers only do what you tell them to do.
8:18They're not magical.
8:19They don't have a mind.
8:22They just know how to perform calculations really,
8:24really quickly.
8:26But you have to tell them what calculations to do.
8:32Computers don't know anything.
8:34All right.
8:35We've come to that.
8:40Let's go into the types of knowledge.
8:44The first type of knowledge is declarative knowledge.
8:48And those are things like statements of fact.
8:50And this is where my email came into play.
8:53If you read it all the way to the bottom,
8:55you would have entered a raffle.
8:57So a statement of fact for today's lecture
8:59is, someone will win a prize before class ends.
9:03And the prize was a Google Cardboard.
9:06Google state-of-the-art virtual reality glasses.
9:09And I have them right here.
9:14Yea.
9:15I delivered on my promise.
9:18That's a statement of fact.
9:20So pretend I'm a machine.
9:22OK?
9:23I don't know anything except what you tell me.
9:26I don't know.
9:28I know that you tell me this statement.
9:30I'm like, OK.
9:31But how is someone going to win a Google Cardboard
9:33before class ends, right?
9:35That's where imperative knowledge comes in.
9:37Imperative knowledge is the recipe, or the how-to,
9:39or the sequence of steps.
9:42Sorry.
9:43That's just my funny for that one.
9:47So the sequence of steps is imperative knowledge.
9:53If I'm a machine, you need to tell me
9:57how someone will win a Google Cardboard before class.
10:00If I follow these steps, then technically,
10:02I should reach a conclusion.
10:06Step one, I think we've already done that.
10:08Whoever wanted to sign up has signed up.
10:11Now I'm going to open my IDE.
10:13I'm just basically being a machine
10:14and following the steps that you've told me.
10:17The IDE that we're using in this class is called Anaconda.
10:21I'm just scrolling down to the bottom.
10:25Hopefully, you've installed it in problem set zero.
10:28I've opened my IDE.
10:30I'm going to follow the next set of instructions.
10:34I'm going to choose a random number between the first
10:36and the nth responder.
10:39Now, I'm going to actually use Python to do this .
10:42And this is also an example of how just
10:44a really simple task in your life,
10:46you can use computers or programming to do that.
10:48Because if I chose a random number,
10:50I might be biased because, for example,
10:51I might like the number 8.
10:53To choose a random number, I'm going to go and say, OK,
10:57where's the list of responders?
10:58It starts at 15.
10:59Actually, it starts at 16 because that's me.
11:03We're going to choose a random number between 16
11:05and the end person 266.
11:09Oh, we just got-- oh.
11:11OK.
11:13OK.
11:13I'm going to cut it off right here.
11:15271.
11:15OK.
11:1616 and 271.
11:18Perfect.
11:19OK.
11:20I'm going to choose a random number.
11:21I'm going to go to my IDE.
11:22And you don't need to know how to do this yet,
11:24but by the end of this class, you will.
11:26I'm just going to use Python.
11:29I'm just going to get the random number package that's going
11:31to give me a random number.
11:32I'm going to say random.randint.
11:35And I'm going to choose a random number between 16 and 272,
11:40OK.
11:4175.
11:42OK.
11:43Great.
11:44I chose a random number.
11:45And I'm going to find the number in the responder's sheet.
11:48What was the number again?
11:49Sorry.
11:5175.
11:52OK.
11:54Up we go.
11:56There we go.
11:57Lauren Z-O-V. Yeah.
12:01Nice.
12:02You're here.
12:14Awesome.
12:16All right.
12:17That's an example of me being a machine and also,
12:21at the same time, using Python in my everyday life,
12:23just lecturing, to find a random number.
12:28Try to use Python wherever you can.
12:30And that just gives you practice.
12:34That was fun.
12:35But we're at MIT.
12:37We're MIT students.
12:39And we love numbers here at MIT.
12:41Here's a numerical example that shows
12:44the difference between declarative and imperative
12:46knowledge.
12:50An example of declarative knowledge
12:51is the square root of a number x is y such that y times y
12:54is equal to x.
12:57That's just a statement of fact It's true.
13:02Computers don't know what to do with that.
13:05They don't know what to do with that statement.
13:07But computers do know how to follow a recipe.
13:11Here's a well-known algorithm.
13:13To find the square root of a number x,
13:16let's say x is originally 16, if a computer follows
13:23this algorithm, it's going to start with a guess, g,
13:26let's say, 3.
13:28We're trying to find the square root of 16.
13:30We're going to calculate g times g is 9.
13:34And we're going to ask is if g times g
13:36is close enough to x, then stop and say, g is the answer.
13:39I'm not really happy with 9 being really close to 16.
13:42So I'm going to say, I'm not stopping here.
13:44I'm going to keep going.
13:47If it's not close enough, then I'm
13:48going to make a new guess by averaging g and x over g.
13:52That's x over g here.
13:54And that's the average over there.
13:57And the new average is going to be my new guess.
14:04And that's what it says.
14:05And then, the last step is using the new guess,
14:07repeat the process.
14:08Then we go back to the beginning and repeat the whole process
14:11over and over again.
14:13And that's what the rest of the rows do.
14:15And you keep doing this until you decide
14:16that you're close enough.
14:23What we saw for the imperative knowledge
14:25in the previous numerical example
14:26was the recipe for how to find the square root of x.
14:31What were the three parts of the recipe?
14:33One was a simple sequence of steps.
14:36There were four steps.
14:39The other was a flow of control, so there were
14:42parts where we made decisions.
14:45Are we close enough?
14:46There were parts where we repeated some steps.
14:49At the end, we said, repeat steps 1, 2, 3.
14:52That's the flow of control.
14:55And the last part of the recipe was a way to stop.
14:58You don't want a program that keeps going and going.
15:00Or for a recipe, you don't want to keep baking bread forever.
15:03You want to stop at some point.
15:05Like 10 breads is enough, right?
15:07So you have to have a way of stopping.
15:10In the previous example, the way of stopping
15:12was that we decided we were close enough.
15:15Close enough was maybe being within .01, .001,
15:20whatever you pick.
15:23This recipe is there for an algorithm.
15:26In computer science speak, it's going to be an algorithm.
15:29And that's what we're going to learn about in this class.
15:34We're dealing with computers.
15:35And we actually want to capture a recipe
15:37inside a computer, a computer being a mechanical process.
15:49Historically, there were two different types of computers.
15:55Originally, there were these things
15:57called fixed-program computers.
15:59And I'm old enough to have used something
16:02like this, where there's just numbers and plus, minus,
16:06multiplication, divide, and equal.
16:08But calculators these days are a lot more complicated.
16:11But way back then, an example of a fixed-program computer
16:15is this calculator.
16:16It only knows how to do addition, multiplication,
16:19subtraction, division.
16:20If you want to plot something, you can't.
16:22If you want to go on the internet, send email with it,
16:27you can't.
16:27It can only do this one thing.
16:31And if you wanted to create a machine that did another thing,
16:33then you'd have to create another fixed-program computer
16:37that did a completely separate test.
16:39That's not very great.
16:41That's when stored-program computers came into play.
16:45And these were machines that could store
16:47a sequence of instructions.
16:50And these machines could execute the sequence of instructions.
16:54And you could change the sequence of instructions
16:56and execute this different sequence of instructions.
17:00You could do different tasks in the same machine.
17:03And that's the computer as we know it these days.
17:07The central processing unit is where all of these decisions
17:11get made.
17:11And these are all the peripherals.
17:16The basic machine architecture-- at the heart of every computer
17:20there's just this basic architecture--
17:25and it contains, I guess, four main parts.
17:28The first is the memory.
17:31Input and output is the other one.
17:34The ALU is where all of the operations are done.
17:39And the operations that the ALU can do
17:41are really primitive operations, addition, subtraction,
17:44and so on.
17:46What the memory contains is a bunch of data
17:52and your sequence of instructions.
18:00Interacting with the Arithmetic Logic Unit is the Control Unit.
18:03And the Control Unit contains one program counter.
18:07When you load a sequence of instructions,
18:09the program counter starts at the first sequence.
18:15It starts at the sequence, at the first instruction.
18:18It gets what the instruction is, and it sends it to the ALU.
18:22The ALU asks, what are we doing operations on here?
18:25What's happening?
18:27It might get some data.
18:29If you're adding two numbers, it might get two numbers
18:31from memory.
18:33It might do some operations.
18:34And it might store data back into memory.
18:37And after it's done, the ALU is going to go back,
18:41and the program counter is going to increase
18:43by 1, which means that we're going
18:45to go to the next sequence in the instruction set.
18:50And it just goes linearly, instruction by instruction.
18:53There might be one particular instruction
18:56that does some sort of test.
18:58It's going to say, is this particular value
19:07greater or equal to or the same as this other particular value?
19:11That's a test, an example of a test.
19:13And the test is going to either return true or false.
19:17And depending on the result of that test,
19:20you might either go to the next instruction,
19:24or you might set the program counter
19:26to go all the way back to the beginning, and so on.
19:29You're not just linearly stepping
19:32through all the instructions.
19:33There might be some control flow involved,
19:35where you might skip an instruction,
19:36or start from the beginning, or so on.
19:39And after you're done, when you finished
19:42executing the last instruction, then you
19:44might output something.
19:47That's really the basic way that a computer works.
19:53Just to recap, you have the stored program computer
19:55that contains these sequences of instructions.
19:59The primitive operations that it can do
20:00are addition, subtraction, logic operations, tests--
20:06which are something equal to something else, something
20:08less than, and so on-- and moving data,
20:10so storing data, moving data around, and things like that.
20:14And the interpreter goes through every instruction
20:19and decides whether you're going to go to the next instruction,
20:22skip instructions, or repeat instructions, and so on.
20:28So we've talked about primitives.
20:30And in fact, Alan Turing, who was a really great computer
20:35scientist, he showed that you can compute anything
20:37using the six primitives.
20:38And the six primitives are move left, move right, read, write,
20:46scan, and do nothing.
20:49Using those six instructions and the piece of tape,
20:54he showed that you can compute anything.
20:57And using those six instructions,
21:00programming languages came about that
21:03created a more convenient set of primitives.
21:05You don't have to program in only these six commands.
21:11And one interesting thing, or one really important thing,
21:16that came about from these six primitives
21:19is that if you can compute something in Python,
21:22let's say-- if you write a program that computes something
21:25in Python, then, in theory, you can
21:28write a program that computes the exact same thing
21:31in any other language.
21:32And that's a really powerful statement.
21:36Think about that today when you review your slides.
21:39Think about that again.
21:40That's really powerful.
21:45Once you have your set of primitives
21:49for a particular language, you can start creating expressions.
21:53And these expressions are going to be
21:55combinations of the primitives in the programming language.
22:00And the expressions are going to have some value.
22:02And they're going up some meaning in the programming
22:05language.
22:08Let's do a little bit of a parallel with English
22:10just so you see what I mean.
22:14In English, the primitive constructs
22:15are going to be words.
22:17There's a lot of words in the English language.
22:19Programming languages-- in Python, there are primitives,
22:23but there aren't as many of them.
22:25There are floats, Booleans, these
22:28are numbers, strings, and simple operators,
22:31like addition, subtraction, and so on.
22:35So we have primitive constructs.
22:38Using these primitive constructs,
22:39we can start creating, in English, phrases, sentences,
22:48and the same in programming languages.
22:49In English, we can say something like, "cat, dog, boy.
22:54That, we say, is not syntactically valid.
22:58That's bad syntax.
23:00That's noun, noun, noun.
23:01That doesn't make sense.
23:05What does have good syntax in English is noun, verb, noun.
23:08So, "cat, hugs boy" is syntactically valid.
23:12Similarly, in a programming language,
23:14something like this-- in Python, in this case-- a word
23:18and then the number five doesn't really make sense.
23:20It's not syntactically valid.
23:22But something like operator, operand, operator is OK.
23:28So once you've created these phrases, or these expressions,
23:34that are syntactically valid, you
23:37have to think about the static semantics of your phrase,
23:41or of your expression.
23:45For example, in English, "I are hungry" is good syntax.
23:51But it's weird to say.
23:55We have a pronoun, a verb, and an adjective, which
23:58doesn't really make sense.
23:59"I am hungry" is better.
24:03This does not have good static semantics.
24:07Similarly, in programming languages--
24:09and you'll get the hang of this the more
24:11you do it-- something like this, "3.2 times 5, is OK.
24:15But what does it mean?
24:17What's the meaning to have a word added to a number?
24:22There's no meaning behind that.
24:25Its syntax is OK, because you have
24:28operator, operand, operator.
24:30But it doesn't really make sense to add a number to a word,
24:32for example.
24:36Once you have created these expressions that
24:39are syntactically correct and static, semantically correct,
24:44in English, for example, you think about the semantics.
24:48What's the meaning of the phrase?
24:50In English, you can actually have more than one
24:52meaning to an entire phrase.
24:56In this case, "flying planes can be dangerous"
25:01can have two meanings.
25:02It's the act of flying a plane is dangerous,
25:04or the plane that is in the air is dangerous.
25:08And this might be a cuter example.
25:10"This reading lamp hasn't uttered a word
25:12since I bought it.
25:13What's going on?"
25:15So that has two meanings.
25:16It's playing on the word "reading lamp."
25:21That's in English.
25:21In English, you can have a sentence
25:23that has more than one meaning, that's
25:25syntactically correct and static, semantically correct.
25:28But in programming languages, the program that you write,
25:31the set of instructions that you write, only has one meaning.
25:34Remember, we're coming back to the fact
25:35that the computer only does what you tell it to do.
25:40It's not going to suddenly decide
25:42to add another variable for some reason.
25:46It's just going to execute whatever statements you've
25:49put up.
25:50In programming languages, there's only one meaning.
25:52But the problem that comes into play in programming languages
25:58is it's not the meaning that you might have
25:59intended, as the programmer.
26:03That's where things can go wrong.
26:05And there's going to be a lecture
26:07on debugging a little bit later in the course.
26:10But this is here just to tell you
26:12that if you see an error pop up in your program,
26:16it's just some text that says, error.
26:21For example, if we do something like this,
26:28this is syntactically correct.
26:30Incorrect.
26:31Syntactically incorrect.
26:32See?
26:32There's some angry text right here.
26:36What is going on?
26:37The more you program, the more you'll
26:39get the hang of reading these errors.
26:41But this is basically telling me the line
26:43that I wrote is syntactically incorrect.
26:45And it's pointing to the exact line and says, this is wrong,
26:49so I can go back and fix it as a programmer.
26:55Syntax errors are actually really easily caught by Python.
27:00That was an example of a syntax error.
27:02Static semantic errors can also be
27:04caught by Python as long as, if your program has some decisions
27:09to make, as long as you've gone down the branch where
27:13the static semantic error happens.
27:18And this is probably going to be the most frustrating one,
27:22especially as you're starting out.
27:23The program might do something different than what
27:25you expected it to do.
27:27And that's not because the program suddenly-- for example,
27:32you expected the program to give you an output of 0
27:34for a certain test case, and the output that you got was 10.
27:37Well, the program didn't suddenly
27:39decide to change its answer to 10.
27:42It just executed the program that you wrote.
27:48That's the case where the program gave you
27:50a different answer than expected.
27:53Programs might crash, which means they stop running.
27:55That's OK.
27:57Just go back to your code and figure out what was wrong.
28:00And another example of a different meaning
28:03than what you intended was maybe the program won't stop.
28:06It's also OK.
28:07There are ways to stop it besides restarting
28:10the computer.
28:12So then Python programs are going
28:17to be sequences of definitions and commands.
28:20We're going to have expressions that are going to be evaluated
28:25and commands that tell the interpreter to do something.
28:33If you've done problem set 0, you'll
28:35see that you can type commands directly
28:37in the shell here, which is the part on the right where
28:40I did some really simple things, 2 plus 4.
28:44Or you can type commands up in here, on the left-hand side,
28:49and then run your program.
28:52Notice that, well, we'll talk about this-- I
28:54won't talk about this now.
28:55But these are-- on the right-hand side, typically,
28:59you write very simple commands just if you're
29:01testing something out.
29:03And on the left-hand side here in the editor,
29:04you write more lines and more complicated programs.
29:15Now we're going to start talking about Python.
29:18And in Python, we're going to come back to this,
29:20everything is an object.
29:23And Python programs manipulate these data objects.
29:27All objects in Python are going to have a type.
29:30And the type is going to tell Python the kinds of operations
29:34that you can do on these objects.
29:37If an object is the number five, for example,
29:39you can add the number to another number,
29:42subtract the number, take it to the power of something,
29:45and so on.
29:47As a more general example, for example, I am a human.
29:51So that's my type.
29:52And I can walk, speak English, et cetera.
29:55Chewbacca is going to be a type Wookie.
29:59He can walk, do that sound that I can't do.
30:02He can do that, but I can't.
30:04I'm not even going to try, and so on.
30:09Once you have these Python objects,
30:11everything is an object in Python.
30:14There are actually two types of objects.
30:16One are scalar objects.
30:18That means these are very basic objects in Python from which
30:21everything can be made.
30:24These are scalar objects.
30:26That can't be subdivided.
30:28The other type of object is a non-scalar object.
30:31And these are objects that have some internal structure.
30:33For example, the number five is a scalar
30:36object because it can't be subdivided.
30:39But a list of numbers, for example, 5, 6,
30:417,8, is going to be a non-scalar object
30:45because you can subdivide it.
30:46You can subdivide it into-- you can find parts to it.
30:53It's made up of a sequence of numbers.
30:58Here's the list of all of the scalar objects in Python.
31:01We have integers, for example, all of the whole numbers.
31:05Floats, which are all of the real numbers, anything
31:10with a decimal.
31:11Bools are Booleans.
31:13There's only two values to Booleans.
31:16That's True and False.
31:18Note the capitalization, capital T and capital F.
31:23And this other thing called NoneType.
31:24It's special.
31:26It has only one value called None.
31:28And it represents the absence of a type.
31:30And it sometimes comes in handy for some programs.
31:34If you want to find the type of an object,
31:36you can use this special command called type.
31:39And then in the parentheses, you put down
31:41what you want to find the type of.
31:44You can write into the shell "type of 5,"
31:47and the shell will tell you, that's an integer.
31:52If you happen to want to convert between two different types,
31:56Python allows you to do that.
31:58And to do that, you put the type that you
32:01want to convert to right before the object
32:03that you want to convert to.
32:05So float(3) will convert the integer 3 to the float 3.0.
32:12And similarly, you can convert any float into an integer.
32:16And converting to an integer just truncates.
32:20It just takes away the decimal and whatever's
32:22after it-- it does not round-- and keeps just the integer
32:26part.
32:30For this slide, I'm going to talk about it.
32:31But if you'd like if you have the slides up,
32:35go to go to this exercise.
32:37And after I'm done talking about the slide,
32:41we'll see what people think for that exercise.
32:45One of the most important things that you
32:47can do in basically any programming,
32:51in Python also, is to print things out.
32:55Printing out is how you interact with the user.
33:00To print things out, you use the print command.
33:04If you're in the shell, if you simply type "3 plus 2,"
33:07you do see a value here.
33:09Five, right?
33:11But that's not actually printing something out.
33:13And that becomes apparent when you actually
33:18type things into the editor.
33:19If you just do "3 plus 2," and you run the program-- that's
33:23the green button here-- you see on the right-hand side here,
33:26it ran my program.
33:27But it didn't actually print anything.
33:30If you type this into the console,
33:32it does show you this value, but that's
33:33just like peeking into the value for you as a programmer.
33:39It's not actually printing it out to anyone.
33:41If you want to print something out,
33:42you have to use the print statement like that.
33:47In this case, this is actually going to print this number
33:50five to the console.
33:58That's basically what it says.
33:59It just tells you it's an interaction within the shell
34:01only.
34:02It's not interacting with anyone else.
34:04And if you don't have any "Out," that
34:06means it got printed out to the console.
34:09All right.
34:09We talked a little bit about objects.
34:13Once you have objects, you can combine objects and operators
34:16to form these expressions.
34:17And each expression is going to have a value.
34:19So an expression evaluates to a value.
34:22The syntax for an expression is going
34:24to be object, operator, object, like that.
34:30And these are some operators you can do on ints and floats.
34:34There's the typical ones, addition, subtraction,
34:36multiplication, and division.
34:38If, for the first three, the answer
34:43that you get-- the type of the answer that you get--
34:45is going to depend on the type of your variables.
34:48If both of the variables of the operands are integers,
34:52then the result you're going to get is of type integer.
34:55But if at least one of them is a float, then
34:56the result you're going to get is a float.
34:58Division is a little bit special in that
35:02no matter what the operands are, the result
35:04is always going to be a float.
35:09The other operations you can do, and these are also useful,
35:14are the remainder, so the percent sign.
35:19If you use the percent sign between two operands,
35:22that's going to give you the remainder when you divide i
35:25by j.
35:28And raising something to the power of something else
35:30is using the star star operator.
35:32And i star stars j is going to take i to the power of j.
35:41These operations have the typical precedence
35:43that you might expect in math, for example.
35:47And if you'd like to put precedence
35:49toward some other operations, you
35:50can use parentheses to do that.
36:01All right.
36:03So we have ways of creating expressions.
36:07And we have operations we can do on objects.
36:13But what's going to be useful is to be able to save values
36:19to some name.
36:21And the name is going to be something that you pick.
36:24And it should be a descriptive name.
36:27And when you save the value to a name,
36:32you're going to be able to access that value later
36:36on in your program.
36:37And that's very useful.
36:40To save a value to a variable name, you use the equal sign.
36:49And the equal sign is an assignment.
36:51It assigns the right-hand side, which
36:53is a value, to the left-hand side, which
36:55is going to be a variable name.
36:59In this case, I assigned the float 3.14159
37:03to the variable pi.
37:05And in the second line, I'm going
37:08to take this expression, 22 divided by 7,
37:10I'm going to evaluate it.
37:13It's going to come up with some decimal number.
37:16And I'm going to save it into the variable pi_approx.
37:19values are stored in memory.
37:21And this assignment in Python, we
37:22say the assignment binds the name to the value.
37:26When you use that name later on in your program,
37:30you're going to be referring to the value in memory.
37:35And if you ever want to refer to the value
37:37later on in your code, you just simply type
37:39the name of the variable that you've assigned it to.
37:44So why do we want to give names to expressions?
37:48Well, you want to reuse the names instead of the values.
37:51And it makes your code look a lot nicer.
37:54This is a piece of code that calculates
37:56the area of a circle.
37:59And notice, I've assigned a variable pi to 3.14159.
38:03I've assigned another variable called radius to be 2.2.
38:07And then, later on in my code, I have another line
38:09that says area-- this is another variable-- is
38:12equal to-- this is an assignment--
38:15to this expression.
38:17And this expression is referring to these variable names, pi
38:23and radius.
38:24And it's going look up their values in memory.
38:26And it's going to replace these variable names
38:29with those values.
38:30And it's going to do the calculation for me.
38:32And in the end, this whole expression
38:34is going to be replaced by one number.
38:36And it's going to be the float.
38:40Here's another exercise, while I'm talking about the slide.
38:45I do want to make a note about programming versus math.
38:49In math, you're often presented with a problem
38:55that says, solve for x.
38:57x plus y is equal to something something.
39:00Solve for x, for example.
39:03That's coming back to the fact that computers don't
39:09know what to do with that.
39:10Computers need to be told what to do.
39:12In programming, if you want to solve for x,
39:14you need to tell the computer exactly how to solve for x.
39:18You need to figure out what formula
39:20you need to give the computer in order to be
39:22able to solve for x.
39:25That means always in programming the right-hand side is
39:29going to be an expression.
39:33It's something that's going to be evaluated to a value.
39:35And the left-hand side is always a variable.
39:39It's going to be an assignment.
39:40The equal sign is not like in math
39:43where you can have a lot of things to the left
39:45and a lot of things to the right of the equal sign.
39:47There's only one thing to the left of the equal sign.
39:49And that's going to be a variable.
39:50An equal sign stands for an assignment.
39:53Once we've created expressions, and we have these assignments,
39:57you can rebind variable names using new assignment
39:59statements.
40:03Let's look at an example for that.
40:05Let's say this is our memory.
40:07Let's type back in the example with finding the radius.
40:13Let's say, pi is equal to 3.14.
40:19In memory, we're going to create this value 3.14.
40:22We're going to bind it to the variable named pi.
40:28Next line, radius is equal to 2.2.
40:31In memory, we're creating this value 2.2.
40:35And we're going to bind it to the variable named radius.
40:40Then we have this expression here.
40:44It's going to substitute the values for pi
40:46from memory and the value for radius from memory.
40:49It's going to calculate the value that this expression
40:54evaluates to.
40:56It's going to pop that into the memory.
40:57And it's going to assign-- because we're
40:59using the equal sign-- it's going
41:01to assign that value to that variable area.
41:08Now, let's say we rebind radius to be something else.
41:14Radius i is bound to the value 2.2.
41:21But when we do this line, radius is equal to radius plus 1,
41:24we're going to take away the binding to 2.2.
41:27We're going to do this calculation.
41:29The new value is 3.2.
41:31And we're going to rebind that value to that same variable.
41:38In memory, notice we're still going
41:40to have this value, 2.2, floating around.
41:43But we've lost the handle for it.
41:46There's no way to get it back.
41:48It's just in memory sitting there.
41:52At some point, it might get collected by what
41:55we call the garbage collector.
41:56In Python, And it'll retrieve these lost values,
42:00and it'll reuse them for new values, and things like that.
42:05But radius now points to the new value.
42:08We can never get back 2.2.
42:13And that's it.
42:16The value of area-- notice, this is very important.
42:18The value of area did not change.
42:23And it did not change because these are all the instructions
42:26we told the computer to do.
42:28We just told it to change radius to be radius plus 1.
42:33We never told it to recalculate the value of area.
42:37If I copied that line down here, then the value of area
42:41would change.
42:42But we never told it to do that.
42:44The computer only does what we tell it to do.
42:46That's the last thing.
42:47Next lecture, we're going to talk about adding control
42:51flow to our programs, so how do you tell the computer
42:53to do one thing or another?
42:55All right.

Lecture Notes - lecture 1 py

Source: https://ocw.mit.edu/courses/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/920cc911b6eb5747f2ccd431bbc4306b_lec1.py

lecture 1 py

pi = 3.14159
radius = 2.2
# area of circle equation <- this is a comment
area = pi*(radius**2)
print(area)

# change values of radius <- another comment
# use comments to help others understand what you are doing in code
radius = radius + 1
print(area)     # area doesn't change
area = pi*(radius**2)
print(area)


#############################
#### COMMENTING LINES #######
#############################
# to comment MANY lines at a time, highlight all of them then CTRL+1
# do CTRL+1 again to uncomment them
# try it on the next few lines below!

#area = pi*(radius**2)
#print(area)
#radius = radius + 1
#area = pi*(radius**2)
#print(area)

#############################
#### AUTOCOMPLETE #######
#############################
# Spyder can autocomplete names for you
# start typing a variable name defined in your program and hit tab 
# before you finish typing -- try it below

# define a variable
a_very_long_variable_name_dont_name_them_this_long_pls = 0

# below, start typing a_ve then hit tab... cool, right!
# use autocomplete to change the value of that variable to 1

# use autocomplete to write a line that prints the value of that long variable
# notice that Spyder also automatically adds the closed parentheses for you!

pdf-Slides for Lecture 1

Source:https://ocw.mit.edu/courses/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/resources/mit6_0001f16_lec1/
IPFS:QmemB25bVuN2fuiAq3JaDM4J5MYit6HfCCsU3EFTWL7wpF


Problem Set 1

Source:https://ocw.mit.edu/courses/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/resources/mit6_0001f16_ps1/
IPFS:QmbxaDU9U4hquK4Dhb365nD5qG5eEFUM6NABqXRaux6tRB

Additional Python Resources

Source:https://ocw.mit.edu/courses/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/resources/mit6_0001f16_additional/
IPFS:QmYWPVdHEbhmdFXNR9R46ey5eykyFPeCZ1joXE6z28L1VB

Additional Python Resources:

If you're having trouble with a particular concept or simply want to have access to more information, try one of the following links.

DOCUMENTATION

does, examples of correct syntax, what the various libraries are, etc.

TEXTBOOKS/TUTORIALS

tutorial sequence

DEBUGGING

  • [Python Tutor] - an excellent way to actually visualize how the interpreter actually reads and executes

your code

  • [DiffChecker] - compares two sets of text and shows you which lines are different
  • [Debugging in Python] - steps you can take to try to debug your program

OTHER Q&A

  • [Stack Overflow] - a large Q&A forum for programming concepts (not just Python). Try searching here

before you post on the edX forum, and you may find that someone has already answered your question.

MORE PRACTICE PROBLEMS

  • [Python Challenge] - a series of puzzles you can try to test your Python abilities
  • [Project Euler] - additional programming challenges you can try once your Python knowledge becomes

stronger; problems are sorted by increasing difficulty

  • [Coding Bat] - problems you can solve within an online interpreter
  • [Codewars] - improve your skills by training on real code challenges

MIT OpenCourseWare https://ocw.mit.edu 6.0001 Introduction to Computer Science and Programming in Python Fall 2016 For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms.

2

mit-test-course/2/MIT6_0001F16_Lecture_02_300k.mp4
https://ipfs.io/ipfs/QmTFdkMJnzUcwgs1hdoF7qtADE2NqTJVaF9CfgULbzSuA9
QmTFdkMJnzUcwgs1hdoF7qtADE2NqTJVaF9CfgULbzSuA9

mit-test-course/2/ba2947b25b1580e4a84df0ec5dbe5cdd_MIT6_0001F16_Lec2.pdf
https://ipfs.io/ipfs/QmNiZvEh6UmpHLTxw4saN7WdojzBokp2JCbucYzrekoQBK
QmNiZvEh6UmpHLTxw4saN7WdojzBokp2JCbucYzrekoQBK

mit-test-course/2/d6ee838ee4c85ace93a4e170cfd83c03_lec2_branch_loops.py
https://ipfs.io/ipfs/QmPjEzEu56mqeE19Vth9AkDbAxz7wAWg9zMVvF9FZ1UBvK
QmPjEzEu56mqeE19Vth9AkDbAxz7wAWg9zMVvF9FZ1UBvK

3

MIT6_0001F16_Lecture_03_300k.mp4
QmTTCsuhbnjXWuigZLSgKAt4DjFsm78MANo3KUMGcK98s1

88de925a1fb925e46a08bc5f34d029bd_lec3_strings_algos.py
QmYppDgGMptihHA7ixFw2GHvspN8Bw1HY21HtUpQNxi23i

b9b9a82a29e8746db1facfbd30c07940_MIT6_0001F16_Lec3.pdf
QmP2AZfUx8RTqCGamJtPyodFU8dHG8QrBHYKkP79YepEe9

4

MIT6_0001F16_Lecture_04_300k.mp4
QmQuc5zpaJdMfRYxTLyZc5DQuota1FjuJiqgWf8ctGmRsU

6ba59859535f1566dd57a7279aeba5d1_MIT6_0001F16_Lec4.pdf
QmP1p4h21ogMxWeeX2PiDibQbHqWer7ABCsMrfMxEx7QBW

9e8439a27af18817e046ac37333d03f6_lec4_functions.py
QmNtPQncXMYNBnX4NoNfx2ifetrfvrATamdrsjx4u9iQ7c

5

MIT6_0001F16_Lecture_05_300k.mp4
Qmco5sKKQfnWUNP9ZUxLkDhoV6jfjv8L4AdzES7En41AzP

1776670e271578eeb99fc25975f20586_MIT6_0001F16_Lec5.pdf
QmSdxg2inPbK1FSynNdPUka6CUZtEGG6sdPZgxaAgb46GE

cdf5f8e7f109952655f4d253ed955555_lec5_tuples_lists.py
QmThDori5ETa3U27DFpndU7RmsLgG7zjpqGVxAncCupSuc

6


MIT6_0001F16_Lecture_06_300k.mp4
QmVzK3PVETv69Y27UKDfaQQM5um8ByMdYQS3TzD2EkoR42

876348c652c5353daccc96e1b7d577bb_MIT6_0001F16_Lec6.pdf
QmQAqSGJAeoypUMyUnb7hRrziDyRAwymcTGdcaydT5i73s

706228e592761d9c7c1c073f8ba7a6cc_lec6_recursion_dictionaries.py
QmaGhNYnR5yUMYZf4q7qLsNwEW6B7pbLbgJokJBTNSA2FT

7


MIT6_0001F16_Lecture_07_300k.mp4
QmUyiqpAUA91w4Xm2Dz2wPr6kE6wTzA1apwJziTdBysRLw

51bdde43dfd773ba20747ce5d89119ac_MIT6_0001F16_Lec7.pdf
QmcqZoeVrsfBv4Ri6M8KtiLdy3VpKnyznDFhX8zvfd3Qrs

abdd1d61892ccce9be2ad84e52004e07_lec7_debug_except.py
QmeVKCB6ponYr4f72MuNwegukX9t42NTywNHpDPgyNi9ae

8


MIT6_0001F16_Lecture_08_300k.mp4
QmZFSSPndvRfPT2vyehuyEQitfb8CzdYkA7orFAKyvhA4u

7a6f85d03f132dcd9d7592bc4643be1c_MIT6_0001F16_Lec8.pdf
QmdccChFuYBCiLmufEmk6oXCHybaUQiPXajD3c3xMupiaC

0705ac9dcc7e637a0e8e9d97eb258a26_lec8_classes.py
QmQCaZZA75UQ5pAKy8zhcz6Ci8yY13UVHUvsuXmid86GUH

9


MIT6_0001F16_Lecture_09_300k.mp4
QmdENonCipE7TK99i7dFz9paqDUSefR4PFdveEmVi5oXAb

2dd6c75e7b4bd6bd135078e6f3701201_MIT6_0001F16_Lec9.pdf
QmbaJFk4mFRmCbtQybK94etyfRA2LcM22Kfvjbvdf6X8Gw

bf8e8195044d5f6aefc1a455968e2f3e_lec9_inheritance.py
QmQ7UB4PaGBRHvHfDshrASwynvansFVXrp3RNULwhThUsC

10


MIT6_0001F16_Lecture_10_300k.mp4
QmQNooq1g25LFp1Fxj2tfpKKMKi8NbutkhuXNf5Ppo7t5f

066eba6ea6d56a88e56ae325940d4c4c_MIT6_0001F16_Lec10.pdf
QmbyP59ttPKGe5ZNADsgqTsgBF3oYGzhZXFfBhszG2nuPm

bfa32fd241d88ae02cd3157aed232bac_lec10_complexity_part1.py
QmUtgXQXjj2C3qb2UXFrPmKHkFdEjmehk4ZLQhcZ37rEmw

11


MIT6_0001F16_Lecture_11_300k.mp4
QmR7Ned6iZytjpVHVN6W53EZ5Qg4Zd6EkEcXxn8DjYMgrd

bb953fb81d4afa3bc837c16eba613955_MIT6_0001F16_Lec11.pdf
QmNPjN3616QdmEWLPokwuTkLL1vrzcLVRSFLWUcukqtxZL

bdf800867e6762c6758ecd2230178f41_lec11_complexity_part2.py
QmdpwFTFkwnkqWW3CozBBAfeYHchDeVAV7ArkA1dUqbUZ4

12


MIT6_0001F16_Lecture_12_300k.mp4
QmPWidAv5mBrgEcKDVqWe62JaAiwBWs8KZc1S8r3bbJsvY

6425d0dabb1cea1a076b8c46c0ae2da6_MIT6_0001F16_Lec12.pdf
QmToP68Knz71euVuntRWtz6UshRoiRssELJNFMeP1f2sR5

310536cd5f5aa1fc0c11726ce13c565e_lec12_sorting.py
QmbV8ct8DEQyRGRDSX4PaQBXk8r8ryYLDNwTa2buC7kcP5