Lec 3 | MIT 6.00 Introduction to Computer Science and Programming, Fall 2008
ฝัง
- เผยแพร่เมื่อ 5 ส.ค. 2024
- Lecture 3: Common code patterns: iterative programs
Instructors: Prof. Eric Grimson, Prof. John Guttag
View the complete course at: ocw.mit.edu/6-00F08
License: Creative Commons BY-NC-SA
More information at ocw.mit.edu/terms
More courses at ocw.mit.edu
When i starting watching these videos I said, "Boy, understanding these will be painful" but these proffesors make it easy and simple. Good job MIT :D
Ur smart
python is a super simple and easy language to learn as well.
there is a reason MIT is so expensive ;)
Professors in MIT really know how to teach people.
Even a non-english programmer like me in Taiwan still understand what they are teaching and enjoy the online courses so much~
MIT OpenCourse rocks~
i love his dad jokes and friendly way of teaching
Give him award for one of the best teacher
After less than two weeks worth of the lectures, this series has already surpassed what I learned when I audited a course at my local community college. This is why MIT is MIT, THANK YOU for making this available!
Thank you MIT for helping me become a good programmer
When the lecturer wrote on the board, i feel an urge inside me to take notes. But lol i am watching this video with my sleepy eyes, sitting on the bed. i hope i can restart learning programming after these 12 lessons.
I love the sweet " :) Good morning" written on the board! Really makes you feel at home, even if I am watching this hundreds of km and a couple of years away!
I have tried learning programming 4 times in the past. It FINALLY clicked! Thank you!
im so grateful for MIT uploading such valuable lectures! Thank you so much
So the lecturers where I went to uni put me off coding for decades. You guys are making it really nice and easy, thanks.
I want to thank MIT for providing these lectures and the lecturers for them allowing it to be done. Given the chance I would have attended MIT specializing in software engineering, but since I could not, this is almost like being in the classroom.
Jesus guys, he's not THAT funny.
It's amazing that we can re live this whole course for free. What a time to be alive.
The flowchart is a good idea. It really helps to visualize your program. In koffice (ubuntu), there's a decent flowchart program called Kivio if anyone is trying to find one.
6:14 mmmlpl
Lpppl
L
Llllll
Lop l
Plppp
P
P
P
P
Great teachers make great institutions. Thanks for the videos MIT!!
I`m currently taking Intro Programming Logic and we are doing flowchart strucuture and I find it quite easy and Interesting!! LOVE MIT!
THANK YOU MIT!!!! This is an AWESOME resource!
WE NEED MORE TEACHERS LIKE THIS
KEEP UP THE GOOD WORK
These videos are extremely helpful...
I'm trying to gain as much knowledge as I can before I begin taking classes this fall for network management...
I'm very interested in programming.
This is a great starting point tool.
I'm sorry but the comment on keeping nerds in a museum had me cracking up .. Keep em coming!!
This is probably the best resource I have ever found on the net. I wish all of the schools that offer "Online classes" would provide this type of instruction instead of a guided self study course which is basically all it is. I have learned more in 1 day here than in $13,000 worth of Online Classes...
24:30, shouldn't the second "if" and "else" statements be indented after the "while" statement so that we are sure 'ans * ans', is not greater than 'x'?
gonna watch them all. Thanks MIT
hahah John is alive. Prof Eric thanks for such a great class not bad for a couple years old .
I believe these same courses are offered in a workabl form via edx.org. Look for MITX CS 50 i believe its called. there is 2 different courses. This is part 1 of 2. This is how i learned how to code in python. Very good courses. Really get your mind thinking in a programmatic way as opposed to some of the other introductory options out there.
Adjustment for the code:
divisors = divisors + (i,)
it won`t work unless you type the "," after the variable for the new Python
osama ibrahim thx a lot.
thanks
thanks
Actually you should you should have that in a formatted print statement so you don't have to worry about spaces and it looks cleaner
-string concatenation is a bad habit to learn because once you start programming larger apps it won't scale as well as using joins or string formatting
ie: print ({} is a divisor of {}).format(i, x)
you are my hero
after i watched this video Common code patterns: iterative programs, my insight is very open because the video is very good to give information
Thank you for your helpful and charming lecture.
Thank you sir. I can understand the algorithm and data structure from you
It's very useful, I like this course very much.
This lectures are real tresure.
This is the 3rd lecture I heard. I found it interesting. Perfect squares are just the result of multiplying 2 exact numbers, to form 1 number. For example, 25 is a perfect square because 5 * 5=25. I'm 3 lectures in. I'll hear all his lectures and see what happens for me.
Does the Introduction to Computer Science and Programming Using Python
6.00.1x series that starts August 31, 2016 use Python 3.5?
"...the main thing to keep in mind is the general principle that people are dumb and will make mistakes"
-Prof. Guttag
Heh. Indeed! Another great lecture. Some great points on style and defensive programming - thanks again MIT!
I sure wish I'd watched this before attacking the prime numbers homework assignment... all in all though I'm glad I didn't cuz it really stretched my brain some to wrangle a solution :)
Ah - hey, whaddya know? The class handouts are also available at the MIT parent site! U ROCK MIT!
Agreed. He stated in the first video that this is not a course on Python. He's using the language to illustrate important concepts in computer programming and he clearly knows quite a bit about those.
As the lectures progress the view count slowly decreases... The 1st was view by 3.5 million times and it's down to 346 thousands views...
well, sherlock, do you think people start with the last lecture? even if every viewer sticks to the end, the count for the 1st lecture will always be higher than for the last one.
3.5 million (using the outdated statistics) people want to learn computer science. Only a fraction of them are willing to actually do the *learning* part. That's fine in principle, but there's a massive problem when these same people have the habit of quitting the moment a little effort may be required.
Everyone wants to win the marathon, but nobody's willing to run. Don't be your own worst enemy and keep yourself at the starting point. Very often it is the individual who oppresses themself the worst. Don't guarantee yourself the position of last place.
also, more and more empty seats
@@unholychowders 👍
Ok,
I plan to follow the course through and will look int c++ after. Thanks for responding.
Love the lecture very wonderful
'aaah' I need the loop someway to walk in through them : Great job I always wanted to understand the theory under the surface
Yes you should be able to read and write basic codes after the past 3 lectures, however, you have to remember that the students are working 9-10 hours each week on problem sets and homework in addition to their recitation (where they can ask and receive answers to questions that weren't necessarily covered in the lecture or require clarification). So, unless you have been following the exact curriculum as the students, you will naturally be a bit behind.
Noticing how much lower the views are from the beginning... That's just sad.
+T3chnical R3dn3ck This stuff isn't for everyone.
lol, noticed that too. Still hanging
some people just click on the first one to see what it's about, not because they want to actually study it.. also a lot of people will transition to the ocw site
Some of us already know all this stuff but we are just curious what CS101 is like at MIT
it's just not for everyone. lol.
thanks for this, hope some day I can study at MIT
To do this, you'd use a method in Python.
x = '1952'
print len(x)
When run, it gives you 4.
I love and would like to thank MIT for this, it's the only good source that I actually can use to learn Programing.
PS. For some strange reason (maybe different Python version), I get 'purple' print word, but it yet works flawlessly it's just strange...
SO after making corrections for parenthesis, what was the last problem that must be fixed in order to avoid typeError: can only concatenate tuple (not "int") to tuple. [Time 44 minute]
Excellent
this guy is awesome
You could either manually add up each individual integer of the numbers, which would take a while or write a for loop script where 1952 are all individual numbers in a list.
Would it be better practice to use an equation to find, say, an even number instead of iterating to that number? Will it be important in a long term project to use the least amount of iterations as possible or can the resources of modern day computers withhold iterations to the point we don't have to worry about it? I'm just wondering if using iterations when it is not necessary is bad practice. Even though without iterations we cannot collect each number..help? :)
He has awesome humor, what's wrong with the students over there? :D
They just want to score marks I guess
MIT, not sure if personality is part of a typical MIT student’s personality
MIT student didn't laugh so much i think !🙋
There's no laughing in computer science.
@Shpira He added a comma after i. So, the tuple (i) in the line divisors = divisors + (i) became (i,)
Can any one tell me what program he is using to write the codes? I downloaded python and it doesn't seem to have the "run" function as in this video. Is it so because python is an interpreter and not compiler? thanks
Thanks for your videos!!! Could please help to find homework assignments and exercises concerning the topic. Thanks!
What changes does the prof make at 43:20? I can't see what he did.
what does he throws to whom answer the questions he makes?
Wherr can I find problem sets?
But what WOULD the code look like to add up the # of digits? (that's what I was trying to do)
I tried the code used in 42:48 of the video and apparently python doesn't accept the line. How else can we collect the intermediate values instead?
divisors=divisors + (i)
When I run the code, it showed me this.
TypeError: can only concatenate tuple (not "int") to tuple
attyfarbuckle thank you!
if you look at their website, and go to the problem sets for homework, it tells you to solve for prime numbers. can you help me create a formula to find the 10000th prime?
AWWW THIS IS AWEsOME!!!
the camera guy wasn´t learning at all
so s1 and s2 is a string or tuple?
can anyone help me with the problem he assigned last time? I don't understand the code to find the prime number? It is an equation that computes the variable?
why?
a) Concepts of tuples and lists form the very basis of python
b) After being corrected by a student his reaction is even more puzzled:
"ooh so youre saying that I want this(parenthesis) and not this(square bracket)?...Is that right John? Yes? Okay sorry.."
Nobody can know everything 100% of the time but this is like teaching a course on english and not knowing where to use commas.Like I said, I like his teaching style--it is engaging. And huge thanks to MIT for providing these lecture!
A world of privilege. see how far one must go just to get a decent lecture. if only opportunity were universal.
thanks DnNdr and Levercode
well done thank you !!!
9:57 Demon Cam
3 spooky 5 me
@Anorrea Thank you for this one :)
I am getting an MIT education for free. I'm thankful for this opportunity.
go file and open new window
save as xxxx.py
then start to write your code on the new opened window.
In python 3.3 version print works when it is written like this:
print('--------') or print("-------")
@xejerk and @SandroidHD: Thank you for replying! I have Windows and I use Python IDLE (GUI) but it doesn't have the "run" function. The problem is, unlike in eclipse (in java), I can not go back and make changes in the code in Python IDLE.
are you talking about the uk version of college or US version of college
Good theory...need to do the homework and have a reason to learn it.
@xejerk thanks again! this is exactly what i was looking for. cheers!
i thank mit.
code @ 43:12 does not work for me. even after I added (i,). why?
Can I find anywhere problem sets/assignments related to this course? Thanks
See the course on MIT OpenCourseWare to see the full course materials: ocw.mit.edu/6-00F08. We also recommend you checkout the Scholar version of this course at: ocw.mit.edu/6-00SCS11. It has more materials that might be of help. Best wishes on your studies!
AMAZING
I Thank MIT for these lectures and I learned a lot from these lectures so far, just wondering who this john guy is
i look it up secondary school in the Uk it says its about 10-16 if thats what high school there, then were talking about two different things because 11 years old in the US is about 5 or 6 grade. which is about 3-4 year gap from high school 14 to about 18.
schools in the US is divide maturity levels (i think)
It is possible to get the Homework assignments?
It's also worth mentioning that these MIT students are at MIT because they overachieve and work very hard (of course some are naturally bright without effort but I would bet that a majority are a product of consistent hard-work) so it is very likely they are in fact a few chapters ahead of the lectures (in addition to the problem sets/homework I mentioned in the previous comment). Just keep practicing, thinking and find literature you can read along with.
I wrote a program to check whether a number is prime or composite. I got this error "for i in range(1,x):
TypeError: range() integer end argument expected, got str."
Can someone help me please ??
My code is as follows:
x=raw_input('enter any number')
k=0
for i in range(1,x):
if x%i==0:
k=k+1
if k==2:
print'The number is prime'
else : print 'The number is composite'
Thanks Jeremy I already found it !!! :)
Im in a sixth form college is that the same as high school or is it one level higher (im 17 btw)
Seriously its encourages me to join mit ,harvard,and foreign university
Nice sir. .
Are we supposed to understand how to read and write basic codes after the past 3 lectures. if so im behind :/
@anidude98 for handouts go to MIT's site (search google for this course). the handouts are under "videos", then "related resources"
What on earth is going on from 47:45? What does c mean in the for loop? I have watched over and over at least 10 times and can't figure out what is going on. I understand the overall concept, which is to get the sum of the numbers, but i can't understand the method behind it. I can't understand how the answer comes about. I understand type conversion but get completely lost at 48:30. It just makes no sense. Thanks in advance...
The number 1952 is converted to a string containing 4 characters: "1", "9", "5" and "2", in order. This is what the str(1952) bit is doing. This is then presented to the for loop as the ordered set to iterate over, and on each iteration the variable c contains the element from the set being iterated over, starting with the first ("1") and proceeding in order through the set until all the elements are exhausted. So on the first iteration, the variable c will contain the character "1" (not the number 1, but the "letter" "1", which is codepoint 49 if ascii or unicode is the character set in use). The int(c) in the body of the for loop scans the characters of the string it is given and converts them to the number those digits represent (provided they don't contain characters that aren't a valid string representation of a number, so int('42') is ok, int('hello') is an error). Then this numeric value is accumulated in the variable sumDigits (which therefore takes on the values 0, 1, 10, 15, 17 as the loops proceed). This accumulator is then printed out
Thanks Cyan, i think that's more sense now :) Thanks for explaining
Have you done the homework assignments?
I could watch it before,but now?
Do I have to donate the money first to watch it again ?
I went to a highschool at age 11 as did everyone else in my town. It was even called a 'high school' although the normal UK term is 'secondary school'.
I was glad someone corrected him about the list and tuple syntax. I bet he would have figured it out a bit later though, or John would have corrected him.
@EKBadass hey EK, this is just any old text editor. Say for instance you type many lines of code into your shell. But instead of typing that in every time you can save all the code in a text file. Then when you run the text file in python, you will get back the interpreter with some output (if you specified some output in the code). So he has a text editor open (in this case IDLE) where he is saving lines of code you would of had to type over and over again.
I am in my first year of high school and I am very interested into getting into MIT. What can I do to increase my chances? I get all A's and planning on taking AP Computer Science and most other classes Honors or AP. What else can I do?
athletics and community work, also a letter of recommendation from someone in the faculty at MIT.
i don't have the area that he writes his code in ... i write and execute in the same time in straight line !!
Which programming language was being used for this course?
This course uses Python 2.5.x. See the course on MIT OpenCourseWare for more details at: ocw.mit.edu/6-00F08.
can someone help me with problem set number 2?
he is the best ;)
I don't get the code and correction happening just after the 43 min. mark. I tried to run it but it returns no values. This is the bit of code that ends by saying "divisors = divisors + (i,)." What is going on here?
That is correct, the line of code should be
divisors = divisors + (I,)
Meaning it's adding the desired elements(specified by the if statement) to the variable "devisors"(which starts out as an empty tuple and gets elements added to it)
If this doesn't help, elaborate on your problem a bit more so I can try to help you.
+Josh “DimeADuzen” Abernathy
x = 100
divisors = ()
for i in range(1,x):
if x%i == 0:
divisors = divisors + (i,)
--returns no value
-i'm using python 3.5.1
x=100
divisors =()
for i in range(1,x):
if x%i==0:
divisors=divisors+(i,)
print (divisors)