Lec 2 | MIT 6.00SC Introduction to Computer Science and Programming, Spring 2011
Lecture 2: Core Elements of a Program
Instructor: John Guttag
View the complete course: ocw.mit.edu/6-00SCS11
License: Creative Commons BY-NC-SA
More information at ocw.mit.edu/terms
More courses at ocw.mit.edu
Пікірлер: 143
for those of you using python 3.0 or newer raw_input() was renamed to input()
@xMaverickFPS
7 жыл бұрын
this should be pinned at the top. idk why it was halfway down the page. i was scratching my head for a good 10 minutes before i googled it.
@RanEncounter
7 жыл бұрын
Mental Outlaw This is why the professor said in the first lecture that this course uses phyton 2.
@anandkumat5915
3 жыл бұрын
Ya me too thanks a lot
@politicscigarettes8420
2 жыл бұрын
Holy, didn't expect to see find you here.
For those who didn't get the 22:37 to 24:18 open notepad and write any expression or integer, like write 3, or 'abc' and then click on file, then save as. In save as, write the name of file as script1.py .py is essential part since then computer thinks of that original notepad file as a python script. then change file type to all types. You have now a separate script. Ok, now what? Open the Python IDLE Shell, or you might already have opened it like in the video. Now click on Files and then click Open, then select script1.py which now opens in another shell. For version 3 of Python, when you write print, do not give any space and use parentheses like print(type('a')) and then save it from file corner then hit F5. Your IDLE will give you results. I am very new to this programming concept and thus it took me a lot to figure this out, which would have been an obvious thing for a CS student. Its for those who were like me and didn't get it.
@IanMahetiMbano
7 жыл бұрын
Thank you Mehnur Z., l just did it in the 3.6.1 version
This Comment Made by PrestigeSeattle really helped. For understanding 35:49 if x%2 == 0; print 'Even' else; print 'Odd' if x%3 != 0; print 'And not divisible by 3' This "%" symbol is asking you for a remainder, so any odd number divided by 2 is going to have a remainder of one. The "==" is checking if it's equal The "!=" is checking if it's not equal The code in english would say: "If x divided by 2 has a remainder of 0, print "Even". Otherwise print "Odd." Also, if x divided by 3 has a remainder that isn't 0, print "And not divisible by 3"
when he threw the candy it reminded me of micheal scott n then i thought i wish micheal scott was teaching the lecture and then i went to netflix and put on the office
more great stuff from MIT - thank you for posting these lectures, it's great to have the 2008 and 2011 classes available - I'm especially looking forward to the recitations in the 2011 classes. Lots of great examples and challenging problems to solve in the supplemental material from the classes, also thank you for all the references to reading material for the course!!!
Thank you so much MIT. Seriously, this is beyond amazing what you've provided to people who are otherwise unable to attend MIT.
Excellent teacher and I believe that's the real beauty of MIT Open Courseware. There are many, many teaching tools and videos on computer sciences, but it's very difficult to find well developed teachers, rather professors in this context, such as those found here.
Any programming you do between now and when school starts is most likely going to help you. I wouldnt worry too much about what version youre going to end up using in school because while they are different, its not such a huge leap that it will cause you many problems.
Really like this guy. I was trying to do the Spring 2008 Intro course, but I couldn't make out the text on the programs he was using. This one is much better.
It's a series that goes over it piece by piece.... It's an actual course. Most of the time the first session is mostly administrative, and end of the first through the second are typically very simple concepts in intro courses.
Wow. It was my dream to attend MIT.. now its coming true! Thanks to OCW.
Oh man I love this guy.
You know what, my dream was to be an MIT Computer Science Student but I couldn't make it unfortunately. And now I'm in MIT Classroom, learning from its great lecturers. Thank you so much MIT community and many thanks to the technology.
script is a text that changed the option "view" to python (add-on). How to create a new text is to go to destop or any where, right-click and choose new -> new text.
@NganLe-ty5nd
10 жыл бұрын
and from python choose option "file" you can open that text.
@NganLe-ty5nd
10 жыл бұрын
this actually mentioned from the beginning of the video, but not very clearly in my opinion.
The conditional checking divisibility by 3 was nested in the 'else' so it would only be evaluated if the number entered were odd.
You can find the recitation on the website of the whole course. Just follow the link in the description, press "Get started" and go to this lecture's page.
At 20:00, When he enters int('.0'), he uses quotation marks, but while entering int(2.1), he doesn't. I get no error without quotes and an error with quotes in both cases.(Using Python 2.5.4)
You can do integer division in python 3. Just type two slashes between the operands instead of one.
open it from IDLE. menu->file->open or drag script onto IDLE's icon
Thanks so much for the free lectures!
Actually in Python 3 there's only "input" but it behaves like "raw_input" from Python 2.
Thank You MIT!!!
Because the "divisible by 3" check is only applied to odd numbers, in that code example
Fascinating lecture!!!
i loved this lecture!
he use python 2 and there is python 3 which it is different for example at 13:25 he said when we type 3/2 it will type 1 but in python 3 it will type 1.5
if x%2 == 0; print 'Even' else; print 'Odd' if x%3 != 0; print 'And not divisible by 3' This "%" symbol is asking you for a remainder, so any odd number divided by 2 is going to have a remainder of one. The "==" is checking if it's equal The "!=" is checking if it's not equal The code in english would say: "If x divided by 2 has a remainder of 0, print "Even". Otherwise print "Odd." Also, if x divided by 3 has a remainder that isn't 0, print "And not divisible by 3"
This course is getting interesting...
I have a question. At around 36:30 he shows you a code that has x==0. Is he using 0 to represent all positive whole numbers
Great lecturer !
PSA: Doing integer division in Python 2 (3/2=1) is the same as using the modulo operator in Python 3 (3%2=1) aka "dividing with a remainder".
40:49 what is that character ...if x%3 ?= 0: print 'And not divisible by 3' damn 480p res. 1 doesn't make sense and is giving me a syntax err... else conditional is giving me errors too... maybe wrong Python version? I DL'ed it from the Courseware site's link - 2.7.3.... wtf...
Tell me please which version is better to install 2.5 or 2.7 ?
is this python 2 or 3? i'm assuming 2, because "raw_input" doesn't work with 3.
Hi there I am going to study Computer Science in this fall and i don't know with what version of python they are going to teach me. Does it affect me in bad way if i learn using python with 2.x here and 3.x at University? I am confuse... I need help thank you
34:30 The actual answer to the student's question is that python returns a ValueError
Im a bit new to this - i have the shell/IDLE but how do i open a script?
In Phyton 3.x it is x=int (input('Enter an intenger: ')) if x%2 == 0: print ('Even') else: print ('Odd') if (x%3 != 0): print ('And not divisible by 3') So, not ; sign, : sign
@mahnoorzulfiqar4499
7 жыл бұрын
thanks
what is d diff between cs6.00 and 6.00sc.frm content point of view?
I'm so confused.. I have the python shell program but how do I run it like he did at about 29:04?
@MrZmurcht
8 жыл бұрын
+vanchark You are probably only looking at the *shell* You have to open a new file, write your code in there, save it and the run it (or use F5) it will then run in the shell. You basicly need 2 windows and they look very much the same, thats a bit confusing at the beginning
Are those remote control cameras on a tripod recording the lecture?!
Did they uploaded the video in 0.75x?
I have installed python 3.7 but I can't find the text editor. The IDLE is there, so where will the text editor be? Should I install a normal text editor like notepad++?
@nikhilpatil7218
5 жыл бұрын
You can use a text editor OR an IDE. Idle is an ide. Sublime is a text editor.
I'm pretty sure that 14 is not divisible by 3 either, so why didn't it so as such?
Cool lecturer! Slow and steadily drilling down the points.
how can True and False lead to give False. I am a beginner please help if anyone can
IDLE text editor, shell, debugger. printt statements are useful to debug types of objects Everything is an object types: scalar (indivisible) , non scalar int, float(is an approx to real N), bool, None, str Expression sequence of operartors and operands operators + to add and concatenate strings overloading + is overloaded Type errors are useful convert types int(), str() program = script sequence of commands variables = a name for an object assignment statment comments: explain your thinking input function straight line and branching programs - complexity theory conditional statement - primitive test indentation important can change meaning of the program Programs are intended to be read - punctuation How long straight line program to run - f() the number of lines of code length of time - should be proportional to the amount of input looping constructs = iteration Turing completeness nesting.
You're right! I also just found out that Python 2 rounds off, whereas Python 3 returns a double. DISREGARD MY PSA!
Is Python 2.7.3 compatible with your lectures ?
are we supposed to open 2 IDLE (Python GUI) or 1 IDLE (Python GUI) and 1 Python (command line) ? I open the Python (command line) which doesnt seem to work as shown in the video, doesnt have colour, its black and I cant copy and paste I download the corrrect version but not sure if downloaded the correct format since there are so many under Windows and I dont know which to choose
@UncleBoom
9 жыл бұрын
IDLE Python GUI ... GUI is a Graphical User Interface... Usually thats the part of a program you are ment to interact with... Old comment but in case others were wondering. Command lines are usually not Graphical so to speak, they are for when you know what you want and how to ask for it...
I wonder what is ans times ans times ass equal to?! But really thanks MIT and thanks to this wonderful prof for being awesome
I was trying to run his script for the 'Enter a number' thing, but every time I try, it gives me a syntax error at the 'print y' part in the second line.
@sopcaja
7 жыл бұрын
Hi ! May be you're using python 3.0 or later versions. In such case, you have to put the parentheses for print . So it is now print() rather than just print. For instance: print ("Enter an integer") or a = 3 print(a)
I've tried to run the cube root code (48:20) on Python and it gives me syntax, is it because I'm using 3.0? If it is what should I change to make the program run? ( I already know that raw_input is input )
@blablab97
7 жыл бұрын
No it is not. I am using 2.5.4 and it won't run here either. Gives invalid syntax error too. Gave me syntax error for second x too. x=int(raw_input('Enter an intenger: ')) if x%2 == 0: print 'Even' else: print 'Odd' if x%3 != 0: print 'And not divisible by 3' Anyone has idea what is it ?
@devAsync
7 жыл бұрын
In python 3.0 the print function is written differently, like so: docs.python.org/3/whatsnew/3.0.html I don't know if other functions are written differently as well so... try to install python 2.x it's easier
Does anybody might know where I can find the answers to the problem sets of this course?
@luyao5534
3 жыл бұрын
wonder the same question 8 years later!
LOL yeah, print(f for C programmers) statements for debugging
i was working in Python IDL version 3.5.0 and comparing with the Prof's explanations. I noticed that at 14.04, the professor, says that >>> 3/2 gives 1 but 3.0/2.0 gives 1.5. In this version i am using ( 3.5.0), typing 3/2 gives me 1.5 and not 1. Why the difference? is it because of this version being better that used in lesson?
@user-eg7us1dj4e
8 жыл бұрын
+eric sunda I think it has to do with the later versions (the one you're using) natively dealing with floating point values. In version 2.7 and below, arithmetic calculations with integers will return an integral value, unless you state otherwise. The same does not apply to 3.5.0. In 3.5.0, calculations natively return a floating point type value, if that calculation returns a fractional number and unless you specify you want it to return an int value. That's what I think it is. Take this with a grain of salt. Haven't touched Python in a while, but I think that's what it's about.
@ericsunda5848
8 жыл бұрын
thanks for the clarification. it much clearer now. that means i need to understand each version minute differences if i got to understand what the output is. I do not want my expectations out of a code to be different with actual result. Nevertheless the foundation and basics are the same. Thanks
Wait That's python 2.5.1. But version 3.0 and newer are different. Should i watch 6.00SC ? Is it going to help me now(2018)? Or instead should i independently learn python and develop programming skills?
@mitocw
5 жыл бұрын
We recommend you check out 6.0001 Introduction to Computer Science and Programming in Python, Fall 2016. It is taught with Python 3.x. View the course at: ocw.mit.edu/6-0001F16. Best wishes on your studies!
He says that Java doesn't allow something similar to int(2.1)? I think I can do (in Java): int a = (int) 3.2/1.5; or int b = (int) 2.1; can someone explain?
@arulxz2443
9 жыл бұрын
Ty Heuksal by doing something like int a = (int) 3.2/1.5 you are casting the value of an incompatible type to an int. In other words, you are converting a float or double to an int. What the professor meant is that you cannot use double or float in place of int in Java. Here is a simple example. Define a method which *accepts int* - private void methodA(int x){ } and then call the method like this with an float or double argument - methodA(2.3); Now you will receive an error - incompatible types: possible lossy conversion from double to int. So you cannot use double in place of int in Java but this is possible in Python.
@Angloth
8 жыл бұрын
+Arulx Z Just curious, could you in Java call it - method((int)2.3); Would it be the same as - int a = (int)2.3; method(a);
@arulxz2443
8 жыл бұрын
Yes. It will be the same.
@Angloth
8 жыл бұрын
Arulx Z Thanks!
Thanks
perfect throw
Not really.... because (7/2=3), but (7%2=1) Standard for most programming languages for it to work this way.
Why can't int ('0.0') be converted into int while Just int(0.0) Can Output Simulation Results Int('0.0') Error Int(0.0) 0
@elizabeth-ho
4 жыл бұрын
The number inside the quotes is a floating point number, so it can’t be converted into an int directly. However, int(float(‘0.0’)) would work. Essentially, you can’t skip a step and convert a str into an int if the number in the quotes is not an int.
"The problem with languages like C and Java is that you can indent things and fool the reader of the program." You mean like "goto fail; goto fail;"?
at around @10:11, why does True and False return False?
@kenbobcorn
8 жыл бұрын
+abu saleh Has to do with Boolean algebra, when you get into electrical engineering/computer engineering it is important.
@BinKillEthical
8 жыл бұрын
+abu saleh True and False are two different values true does not equal false there for true and false is false
@Altare1994
8 жыл бұрын
+abu saleh True and False means an object must return True AND False, which is impossible, so it returns False.
great:)
Thought it was a graduate student with nothing to do with very steady arms to hold it up for close to an hour.
ok.. thank you
I honestly disagree that forcing indentation of Python is a good design. I am not sure if the prof has ever ran into the situation that Python shouts at you because you are using tabs to indent and not space. Good intention but very bad implementation.
I love these lectures but I have already made a lot of progress learning Ruby. I know Python and Ruby are very similar but I wish he was using Ruby because I want to stick with that instead of having to learn python for this course. Oh well, he had to choose some language to use as an example I guess. It is what it is...
@IceHawk2504
8 жыл бұрын
+King Alfred Learning another language is going to help you! I'm learning Python right now, and I'm planning on learning another language soonish.
@dickJohnsonpeter
8 жыл бұрын
+Dani Sumthang yea and ive noticed python is easier and more intuitive. Plus the experience already acquired makes it easier to learn another language. I just like to finish one thing before I move on to the next.
Great Work!! Can anyone please point me to the hand outs so that i can download them??
@mitocw
9 жыл бұрын
All the course materials are available on MIT OpenCourse website at ocw.mit.edu/6-00SCS11
@predatorBr
9 жыл бұрын
***** A good sugestion is to try to make tutorials on JAVA classes to.
"ans times ans times ass" :). Seriously though, absolutely brilliant lecture! Thank you, MIT!
I love writing comments that explain what is happening in my code because half the time I'll come back to a program I wrote 6 months ago and never finished and be like... Lol what is this doing?
How can you print the full transcript of this video?
@amir3515
8 жыл бұрын
+Marie Sack copy, paste, print. or highlight, right click, print
what version are they using ?
@mitocw
7 жыл бұрын
Python 2.x
@chaitanyagiri76
7 жыл бұрын
👍
Hahahaha! i was hoping other people caught that too. Good lecture. Thanks MIT
This guy is a freaken boss lol
i am using python 3.6, when i type 3/2, it gives me 1.5
@mitocw
6 жыл бұрын
This class is using Python 2.5.x. If you want to learn programming with Python 3.x, see 6.0001 on MIT OpenCourseWare at: ocw.mit.edu/6-0001F16. Best wishes on your studies!
9:50 It kills me every time
BTW to get nice syntax highlighting in IDLE's edit window, be sure to save scripts to .py extension, then IDLE knows it's a python syntax. also there's some nice IDLE themes here: gist.github(dot)com/AntonioCosta/1554778
Hello there please help me on how i can use python/script 2017
@mitocw
7 жыл бұрын
Do you mean Python 3.5? If you do, you should check out 6.0001: ocw.mit.edu/6-0001F16
@robertbaraza6957
7 жыл бұрын
No am using 3.6..when i just type type (3) in the new file i've created it works well but when i use the print command as told.. print type(3) it's tells me Invalid syntax..
@robertbaraza6957
7 жыл бұрын
even when i try typing (y = raw_input( 'enter a number:')) doesn't work with me.
@mitocw
7 жыл бұрын
You want 6.0001, it will work for you (basically Python 3.x): ocw.mit.edu/6-0001F16 Python 2.x code is incompatible with Python 3.x code: docs.python.org/3/whatsnew/3.0.html#print-is-a-function
@robertbaraza6957
7 жыл бұрын
Okay thanks so much, let me try that..if it goes well ill let you know
Where can I download Python?
@narayanidhar7899
3 жыл бұрын
Go to python typing in google
Seriously, who the hell dislikes this "treasures" ?
48:56
"Ans times ans times ass" LOL I guess this is why I'm not at MIT
@ClearMetalVoltar
9 жыл бұрын
freudian slip!?
@kallmekrissarchivetiktoks8012
6 жыл бұрын
THAT WAS THE BEST THING EVER!!!!
did the girl catch the candy?
Is python an object itself ? XD
48:53 made me laugh.
Hcs a type
Bullcrap. There are three values of bool, aren't there? True, False, None.
@makara2711
2 жыл бұрын
None is not a boolean type, but rather a none type
Very Nice BTW ans times ans times ass did not work for me lol jk very good work
:)
python (dot) org
第一排黑头发扎小辫的是中国妹子啊
Can I have a candy please?
Ans, ans, ans, ans, ass....now stop, and let that program run in IDLE now.