Lec 7 | MIT 6.00 Introduction to Computer Science and Programming, Fall 2008



Lecture 7: Lists and mutability, dictionaries, pseudocode, introduction to efficiency
Instructors: Prof. Eric Grimson, Prof. John Guttag
View the complete course at: http://ocw.mit.edu/6-00F08

License: Creative Commons BY-NC-SA
More information at http://ocw.mit.edu/terms
More courses at http://ocw.mit.edu

source

47 thoughts on “Lec 7 | MIT 6.00 Introduction to Computer Science and Programming, Fall 2008

  • January 13, 2022 at 6:40 am
    Permalink

    It's kinda bizzare, but the north Americans call football soccer.

    There. Fixed it for you

    Reply
  • January 13, 2022 at 6:40 am
    Permalink

    I was recommended this so frequently by YouTube that I finally decided to watch this.

    Reply
  • January 13, 2022 at 6:40 am
    Permalink

    #Code Python 3.8.5
    import math

    def getFloat(requestMsg, errorMsg):
    inputOK = False
    while not inputOK:
    val = float(input(requestMsg))
    if type(val) == type(1.0): inputOK = True
    else: print(errorMsg)
    return val

    base = getFloat("Enter base: ", "Error: base must be a float")
    height = getFloat("Enter height: ", "Error: base must be a float")

    hyp = math.sqrt(base*base + height * height)
    print("Base: " + str(base) + ", height: " + str(height) + ", hyp: " + str(hyp))

    Reply
  • January 13, 2022 at 6:40 am
    Permalink

    #Code Python 3.8.5
    import math
    #Get Base
    inputOK = False
    while not inputOK:
    base = float(input("Enter base: "))
    if type(base) == type(1.0): inputOK = True
    else: print("Error. Base must be a floating point number.")

    #Get Height
    inputOK = False
    while not inputOK:
    height = float(input("Enter height: "))
    if type(height) == type(1.0): inputOK = True
    else: print("Error. Height must be floating point number.")

    hyp = math.sqrt(base*base + height * height)
    print("Base: " + str(base) + ", height: " + str(height) + ", hyp: " + str(hyp))

    Reply
  • January 13, 2022 at 6:40 am
    Permalink

    "Some programs won't stop until I'm old and gray. Some programs won't stop until YOU'RE old and gray"

    Brilliant

    Reply
  • January 13, 2022 at 6:40 am
    Permalink

    for some reason the type check did not work on my computer and I tried it with try/except/else method and it worked charms

    Reply
  • January 13, 2022 at 6:40 am
    Permalink

    inputOK = False
    while not inputOK:
    base = input('Enter base:')
    if type(base) == type(1.0): inputOK = True
    else: print('Enter, Base must be a floating point number.')

    I can't get a correct answer as above code. I always get Enter, Base must be a floating point number. whatever I input. Who knows the problem?

    Reply
  • January 13, 2022 at 6:40 am
    Permalink

    Ok. So when you declare L1 = [1,2,3], are you actually creating a list object or just a variable pointing to an already existing object?
    How about nmbr = 1? Are you creating an object with the value of 1 or is there a sort of universal 1 object to which you just point every time you want a variable to have that value?

    Reply
  • January 13, 2022 at 6:40 am
    Permalink

    Why does the base, height and hyp are converted to str in printing? What difference does it make in just printing out the values?

    Reply
  • January 13, 2022 at 6:40 am
    Permalink

    wow prof grimson is such a great teacher! i wish i have a prof like him when i get to university 🙂

    Reply
  • January 13, 2022 at 6:40 am
    Permalink

    So we can think of the name of the list as a pointer (coming from a C background)

    Reply
  • January 13, 2022 at 6:40 am
    Permalink

    Is anyone else here learning in Python 3.x in order to be up to date and just translating the few differences over from 2.x?

    Reply
  • January 13, 2022 at 6:40 am
    Permalink

    Aw! The girl never got her candy for asking the question at 4:06 :'(

    She didn't want the "a very good question" …

    Reply
  • January 13, 2022 at 6:40 am
    Permalink

    with Python 3.4.3it becomes : 
    def getFloat(requestMasg, errorMsg):
        inputOK = False
        while not inputOK:
            val = float(input(requestMsg))   # accept float value as input instead of a string #
            if type(val)= type(1.0): inputOK = True
            else: print(errorMsg)
        return val

    Reply
  • January 13, 2022 at 6:40 am
    Permalink

    Prof Grimson is such a great teacher! it's hard for me to get distracted while following him.

    Reply
  • January 13, 2022 at 6:40 am
    Permalink

    Is not my desire to be offensive, but it's even more bizarre the fact they call football a sport that people play using their hands, except during few moments, when the ball which is not really a ball must be kicked.

    Reply
  • January 13, 2022 at 6:40 am
    Permalink

    @yurijzagrebnoy You might well be right. However, this is what I keep telling my students: We are not here to learn Python. We are trying to learn programming, we are trying to learn how to build computational models. So basically these two teachers are using Python as a tool to teach students how to program; to get into the habit of thinking algorithimically; and to get into the habit of building computational models for solving problems. Cheerz

    Reply
  • January 13, 2022 at 6:40 am
    Permalink

    I'm I the only one who sees that these guys are quite unfamiliar with the programming language they are trying to teach others?..

    Reply
  • January 13, 2022 at 6:40 am
    Permalink

    lol it's not odd its called football…. it is football. American football should be named American rugby. Or just eggball. Handball is in use…. sorry.

    Reply
  • January 13, 2022 at 6:40 am
    Permalink

    @TheMartingull That's pretty stupid imo, America is a continent. Someone from Canada or Mexico is American too, as you already now. I understand what you mean but if I were American (from Mexico, for example) I wouldn't like you to say that at all. The U.S doesn't own all the American continent.

    Reply

Leave a Reply

Your email address will not be published.