@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
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
@Nisstyre56 I would say premature optimization is worse than needless exception handling. Exception handling as a "flow of control" is becoming popular in interpreted languages because it really doesn't take much time as compared to the actual "interpretation" process. In static languages, if performance is crucial, then, yes, exception handling should be used with care. As for intepreted languages, I'd say bad input is exceptional, wouldn't you?
Maybe he means that when related to lists, "=" means a different thing or has additional meaning (is overload) then "=" in the case of x = -15. Not the ivys binding changes but that the bindings of ivys elements change.
raw_input and input grab strings, not floats, in modern Python versions. Python must have changed raw_input since then. Python now relies heavily on exception handling: try: x = float(raw_input('Enter a number:' )) floatFound = True except: pass
Tsvetan Dimoff From what I heard about that sport is that the ball is just one foot long. That's why football. However, balls for other sports are not one basket nor one volley long. Which is pazzling.
+Serge Balaga I'm pretty sure he means that it's weird the French call soccer football because football is an English word. As opposed to something like piedballe.
@jehugaleahsa You should NEVER simply ignore errors using something like "except: pass". Also, wrapping code in try:, except: clauses needlessly slows down your programs.
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?
Alonso Serrano You're creating both, the list is the object, and the variable is the pointer. The value '1' is immutable, so when you define a = 2, you are not changing the value '1', you are just pointing it to a new value 'two'. Those 'objects' where the values are defined are spaces of memory which will be overwritten when no variable is pointing at them. It's a interesting topic, but Python is a high-level programming language, so I guess that you are not going to hear them talking about memory pointers. But, if you want to learn about them you could look for an explanation in the C programming language, it is a 'mid-level' lenguage and makes use of them.
Mang Juan I guess that Python is a strong typed lenguage, so you can't concatenate two different types of values (integers and strings) and you must convert them to the same type of data. Also there are other 'weak type' lenguages that allows you to make operations in differents type of data like JavaScript
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?
Course materials are available on MIT OpenCourseWare at: ocw.mit.edu/6-00F08. The handouts are under the 'Related Resources' tab for each video. Best wishes on your studies!
Warzix it's not that crazy that we call it soccer after the British came up with name. And we already have another more popular sport in America by the name of football
@jehugaleahsa Yes premature optimization is bad. However imo, you can intelligently handle different inputs without resorting to exception handling in most cases where you know the source of input. e.g. pure vs. impure functions, if a function's output depends totally on the inputs, and not some random source of data, then I say let the interpreter output an error instead of letting it silently pass.
#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))
13:35 sure like the rest of the world except for your weirdos, just joking, I love you guys. Is very funny to realize than we call your "football" as "American football"
#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))
@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.
@@code_explorations, would you settle for " a majority of the countries in the world calls soccer football"? Also, could you give some example of countries which call it soccer apart from America??
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.
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.
@Mrxb0x No you call Football soccer and some weird game that is a poor copy of rugby and is mainly played with hands Football "for some reason". Calling American Football, football is about as stupid as calling basketball football. Also you are alone in this non-sense.
"Some programs won't stop until I'm old and gray. Some programs won't stop until YOU'RE old and gray"
Brilliant
Prof Grimson is such a great teacher! it's hard for me to get distracted while following him.
I was recommended this so frequently by RUclips that I finally decided to watch this.
@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
Finally a very good method. It got me crazy "show dics" at 13:05.
I admittedly got a bit excited when he said "show dics here".
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
Edit: if type(val) == type(1.0):
OR
if isinstance(val, float): inputOK = True
wow prof grimson is such a great teacher! i wish i have a prof like him when i get to university :)
Aw! The girl never got her candy for asking the question at 4:06 :'(
She didn't want the "a very good question" ...
. learning so much so quickly
@Nisstyre56 I would say premature optimization is worse than needless exception handling. Exception handling as a "flow of control" is becoming popular in interpreted languages because it really doesn't take much time as compared to the actual "interpretation" process. In static languages, if performance is crucial, then, yes, exception handling should be used with care. As for intepreted languages, I'd say bad input is exceptional, wouldn't you?
@Mrxb0x Thank you for this very sagacious comment. It really makes a lot of sense.
Maybe he means that when related to lists, "=" means a different thing or has additional meaning (is overload) then "=" in the case of x = -15. Not the ivys binding changes but that the bindings of ivys elements change.
Feels like I'm revising for a first year quiz alongside the professor
I love how Prof Grimson took out the toys and the first thing that came to mind was THE TOWER OF HANOI C:
Absolutely well done and definitely keep it up!!! 👍👍👍👍👍👍
Tower of Hanoi props at the end
go to 13:04, i don't understand why the students weren't laughing...
professor grimsom, glad you're back.
same here :D
Where is prof. fudge knuckle today?
32:44 is there really a computer program that doesn't stop until we are old?
There is, I have discovered a truly remarkable piece of code which this margin is too small to contain.
raw_input and input grab strings, not floats, in modern Python versions. Python must have changed raw_input since then. Python now relies heavily on exception handling:
try:
x = float(raw_input('Enter a number:' ))
floatFound = True
except:
pass
it's bizarre that Americans call football soccer sir
***** America is the greatest country in world, all other countries are run by little girls.
Tsvetan Dimoff From what I heard about that sport is that the ball is just one foot long. That's why football. However, balls for other sports are not one basket nor one volley long. Which is pazzling.
+Serge Balaga I'm pretty sure he means that it's weird the French call soccer football because football is an English word. As opposed to something like piedballe.
lol
Exactly, they call a sport football, that is not played with a ball, but an egg and not with the foot, but the hands. So it should be called hand-egg.
John Guttag is a far better lecturer than Eric Grimson!!
Eric Grimson is a far better lecturer than the rest!! :D
@jehugaleahsa You should NEVER simply ignore errors using something like "except: pass". Also, wrapping code in try:, except: clauses needlessly slows down your programs.
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?
So we can think of the name of the list as a pointer (coming from a C background)
Yes, list name is the reference variable type which is essentially a reference, address or a pointer to the object in memory.
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
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?
Alonso Serrano You're creating both, the list is the object, and the variable is the pointer. The value '1' is immutable, so when you define a = 2, you are not changing the value '1', you are just pointing it to a new value 'two'. Those 'objects' where the values are defined are spaces of memory which will be overwritten when no variable is pointing at them. It's a interesting topic, but Python is a high-level programming language, so I guess that you are not going to hear them talking about memory pointers. But, if you want to learn about them you could look for an explanation in the C programming language, it is a 'mid-level' lenguage and makes use of them.
Nicolas Ortiz Very interesting! Thanks for the reply!
thank you! ~ Good!!!~감사합니다. 건강하십시요.
Why does the base, height and hyp are converted to str in printing? What difference does it make in just printing out the values?
Mang Juan I guess that Python is a strong typed lenguage, so you can't concatenate two different types of values (integers and strings) and you must convert them to the same type of data. Also there are other 'weak type' lenguages that allows you to make operations in differents type of data like JavaScript
12:55 Anybody else laugh here? Can’t believe none of the students reacted 😂
Thank you for the lecture.
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?
it return str in python 3x, so you need to convert str to float as follows code.
Float(input('Enter base:'))
base = input('Enter base: ')
print(type(base))
Run this and you will understand.
lol "showDicts" sounded funny when he said it.
@Mrxb0x soccer is called futbol, not soccer, and its the game that most of the world's population watches
19:20 Omg I loled so hard!
Does anyone know if we can get the actual handout?
Course materials are available on MIT OpenCourseWare at: ocw.mit.edu/6-00F08. The handouts are under the 'Related Resources' tab for each video. Best wishes on your studies!
@warzix no, only ppl from US, all the rest of america call their own language.
Thanks mit
@omkarv Are you sure you didn't mixed them ? Eric Grimson is the funny one.
Warzix it's not that crazy that we call it soccer after the British came up with name. And we already have another more popular sport in America by the name of football
2 gigs 🥲 my laptop now have 16 gigs
@jehugaleahsa Yes premature optimization is bad. However imo, you can intelligently handle different inputs without resorting to exception handling in most cases where you know the source of input. e.g. pure vs. impure functions, if a function's output depends totally on the inputs, and not some random source of data, then I say let the interpreter output an error instead of letting it silently pass.
How did we end up here...0@
@Mrxb0x you call handegg football and football soccer
#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))
wow, is football a french word?
"looks like tag team wrestling" --lol
13:35 sure like the rest of the world except for your weirdos, just joking, I love you guys. Is very funny to realize than we call your "football" as "American football"
#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))
@jillybooty so that if one makes a mistake, the other corrects
You realize that its just over a half of one hundred thousand right?
@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.
It's kinda bizzare, but the north Americans call football soccer.
There. Fixed it for you
@carlosdude1991
He was making those jokes before you or I were born.
👏👏👏👍
I laugh at both showDicts and sqrt.
@TheMartingull from brazil :D
The rest of the world calls Soccer football.
False.
@@code_explorations, would you settle for " a majority of the countries in the world calls soccer football"? Also, could you give some example of countries which call it soccer apart from America??
Shoham Sen Sure. See here: www.businessinsider.com.au/football-vs-soccer-map-2013-12
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.
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.
it is kinda bizarre, but americans call football: "soccer".
@Mrxb0x
No you call Football soccer and some weird game that is a poor copy of rugby and is mainly played with hands Football "for some reason".
Calling American Football, football is about as stupid as calling basketball football.
Also you are alone in this non-sense.
Egads this is some fugly Python code.
I'm I the only one who sees that these guys are quite unfamiliar with the programming language they are trying to teach others?..