# 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

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

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

There. Fixed it for you

• January 13, 2022 at 6:40 am

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

• January 13, 2022 at 6:40 am

Absolutely well done and definitely keep it up!!! 👍👍👍👍👍👍

• January 13, 2022 at 6:40 am

#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))

• January 13, 2022 at 6:40 am

#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))

• January 13, 2022 at 6:40 am

Finally a very good method. It got me crazy "show dics" at 13:05.

• January 13, 2022 at 6:40 am

32:44 is there really a computer program that doesn't stop until we are old?

• January 13, 2022 at 6:40 am

"looks like tag team wrestling" –lol

• January 13, 2022 at 6:40 am

Feels like I'm revising for a first year quiz alongside the professor

• January 13, 2022 at 6:40 am

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

Brilliant

• January 13, 2022 at 6:40 am

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

• January 13, 2022 at 6:40 am

wow, is football a french word?

• January 13, 2022 at 6:40 am

How did we end up here…0@

• January 13, 2022 at 6:40 am

The rest of the world calls Soccer football.

• January 13, 2022 at 6:40 am

Does anyone know if we can get the actual handout?

• January 13, 2022 at 6:40 am

Egads this is some fugly Python code.

• January 13, 2022 at 6:40 am

thank you!  ~ Good!!!~감사합니다. 건강하십시요.

• January 13, 2022 at 6:40 am

The showdicks dictionary?

• January 13, 2022 at 6:40 am

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?

• January 13, 2022 at 6:40 am

Thank you for the lecture.

• January 13, 2022 at 6:40 am

go to 13:04, i don't understand why the students weren't laughing…

• January 13, 2022 at 6:40 am

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?

• January 13, 2022 at 6:40 am

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

• January 13, 2022 at 6:40 am

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

• January 13, 2022 at 6:40 am

Tower of Hanoi props at the end

• January 13, 2022 at 6:40 am

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

• January 13, 2022 at 6:40 am

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?

• January 13, 2022 at 6:40 am

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

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

• January 13, 2022 at 6:40 am

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

• January 13, 2022 at 6:40 am

• January 13, 2022 at 6:40 am

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

• January 13, 2022 at 6:40 am

it's bizarre that Americans call football soccer sir

• January 13, 2022 at 6:40 am

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.

• January 13, 2022 at 6:40 am

You realize that its just over a half of one hundred thousand right?

• January 13, 2022 at 6:40 am

Where is prof. fudge knuckle today?

• January 13, 2022 at 6:40 am

I admittedly got a bit excited when he said "show dics here".

• January 13, 2022 at 6:40 am

@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

• January 13, 2022 at 6:40 am

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

• January 13, 2022 at 6:40 am

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.

• January 13, 2022 at 6:40 am

@omkarv Are you sure you didn't mixed them ? Eric Grimson is the funny one.

• January 13, 2022 at 6:40 am

@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.