2. Branching and Iteration
MIT 6.0001 Introduction to Computer Science and Programming in Python, Fall 2016
View the complete course: ocw.mit.edu/6-0001F16
Instructor: Dr. Ana Bell
In this lecture, Dr. Bell introduces strings and indentation in Python, then discusses basic features of programmatic logic, such as branching, conditionals, iteration, and loops.
License: Creative Commons BY-NC-SA
More information at ocw.mit.edu/terms
More courses at ocw.mit.edu
Пікірлер: 281
To whoever made the subtitles for this 40+ minutes video. Thank you.
@juanjo984184333
4 жыл бұрын
X2
@30_phuc.phanvinh39
3 жыл бұрын
X3.
@HKClasher
3 жыл бұрын
X4
@minhcuong4307
3 жыл бұрын
X5
@externalpoint861
3 жыл бұрын
I think its the speech synthesizer
pre labeling 0:02:08 Strings 0:03:48 (Coding) 0:06:31 Input/Output:print 0:08:21 (Coding) 0:09:57 Input/Output:(" ") 0:12:14 (Coding) 0:14:00 Comparison operators on int , float , string 0:17:06 MIT map 0:18:00 0:19:58 Control flow - branching 0:20:00 0:22:00 0:24:51 Indentation 0:25:46 =vs== 0:28:00 0:28:58 Control flow : while loops 0:31:57 Control flow : while and for loops 0:35:09 Control flow : loops 0:36:44 range (start , stop , step) 0:38:00 0:39:42 (Coding) 0:41:06 break Statement 0:42:26 for vs while loops
@no1reallycaresabout2
2 жыл бұрын
You the real MVP
@ChandravijayAgrawal
2 жыл бұрын
thanks for timestamping every video
@xiaochuansun2638
9 ай бұрын
Thank you, representative.
Love MIT for their CS OCW!!! One comment to add here. When you ask Python to compare two strings (like mentioned in the video "a" > "b" and the result is False) in the backend, Python is comparing their ASCII values (ASCII value of "a" = 97 and ASCII value of "b" = 98. Hence False)
@ChandravijayAgrawal
2 жыл бұрын
thanks
@r4ko276
9 ай бұрын
I dont know if this is entirely true, if i do "ab" == "ba". the result is false. (She said something about lexicographical)
@cerulity32k
4 ай бұрын
@@r4ko276String equality checks if two strings have the same contents. Checking if a string is greater than another string (string inequality) checks if the first string comes after the second string if you were to sort them alphabetically.
I am very lucky and happy to see the smiley ,energetic and enthusiastic face of ANA mam ,when she tried to listen the question that the student asks.BUT AT OTHER PLACES , THIS HAPPENS RARELY BUT NOT IN MIT.
THANK YOU, MIT COURSEWARE and sponsors! ❤️
Kind of wish I got to experience CS at MIT. I loved my professors but this is a professor I know I'd like and learn alot from. Plus MIT's reputation is unmatched.
@PeejTastic
Жыл бұрын
Same, except for me it would've been math/statistics. MIT was the only school I couldn't get accepted into (it was my dream school as a high school student). Having access to this open courseware in my 30s gives me a chance to check some of it out (just in a different subject).
Me and a fellow colleague are leaping into Python (my native language being R). The lecture videos are well-paced and the lecturing style is top notch! I lecture the occasional statistical programming course, and it's not always easy to keep it interesting and engaging like it is here.
Really good for a start with Python. Great work Dr. Bell (and Professor Grimson).
Really liked the Zelda example, loved the flipping table :) Well played, Dr. Bell!
You're a good teacher, accessible yet giving your students a chance to learn.
Wonderful lectures by Prof. Ana Bell. Thank you MIT OCW.
Dr.Bell, can't thank you enough for the great explanation.
Had somebody taught flow control statements as clearly as Dr.Bell my coding journey would have been at stratospheric levels...these lecture ignited my hopes of becoming a good programmer...
you're brilliant Dr. Bell. love your lectures💜
OMG, these are finally in HD!
What a smooth lecture ! Thank you ! You helped me understand Python. My professor did a terrible job teaching this. Thanks MIT !
thank you Dr Ana Bell this was a really helpful and fun course !
This is the best MIT has to offer. Good thing its free.
Thank you open courseware for providing such high quality leacture and materials..hope you have a great day😊
Dr. Ana Bell is great teacher.❤❤❤ You are very good at explaining and in all perspective. You are best.Thanks MIT for Dr. Ana Bell. Thanks MIT for OCW.MIT is best and doing great work.
She is so adorable, I really love her lessons. Thanks MIT.
I really love this lectures and completed my some basic python syntax and basic algorithm related concepts thanks for this contribution.
the best lecture on python, the reason why mit is a top college in the world
Superb video of excellent teaching. I wish she was my professor when I was an undergrad.
thank you Dr Bell ! , rock on! better explained than my school lessons 4sure
Dr Bell, you are the best❤❤
For those curious about how Dr. Bell commented out certain lines of code here's the shortcut list, Single line comment Ctrl + 1 Multi-line comment select the lines to be commented Ctrl + 4 Unblock Multi-line comment Ctrl + 5 P.S: Got this from Stack Overflow so due credit to the actual authors for this query.
AMAZING LECTURE
Excellent lecture. Makes me wish I were back as a student. this is the best explanation of for & while loops I have seen. I wish I could take this course, but I no longer live in Boston.
Thanking MIT OCW Please upload more 💙
Dr Bell Your class was comfortable and interesting. Thank you for not writing on the board.
Thanks a lot Dr. Anna Bell
VERY VERY thanks ,MIT open coursewarde.
best python tutorial ever
OBLI WATCHED THIS FROM SRI LANKA.TO BE HONEST NONE OF UNIVERSITIES OF SRI LANKA PROVIDE GOOD LECTURES LIKE THESE
This is awesome!!!
Adorable teacher. Excellent lecture.
her legend of zelda example was a really excellent example to use and keep students engaged
mam, i really loved the way you teach.
very helpful, thank you
you can actually use a for-loop to get input in Python - create a simple iterator class where __next__ returns a value from a call to input().
I love your problem sets. They really made me want to hit my head with a piece of wood over and over again. Real learning guys.
@user-kp5kg5dl8h
6 жыл бұрын
Jordy Muñoz Aravena The ones found on the website? The ones that make you have to look up everything yourself before you can even do them?
@shivang581
5 жыл бұрын
Hey! Could you please share the link of the problem sets? Thank You!
@ViktorMath
5 жыл бұрын
@@shivang581 Here you are ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/assignments/
@shivang581
5 жыл бұрын
@@ViktorMath THANK YOU SO VERY MUCH!
nice lectures delivery....dr bell
thank you ,mit
Ana Bell ❤❤
Dr Bell is a legend
شكرا اوي
SHE IS SUCH A GOOD TEACHER
Amazing clasess
thank you mit
It would help that when Ana points to the board and makes a comment, the camera also shows the board and not the picture of Ana talking. thanks for the free lectures
Присоединяюсь. к отзыву "walawave ", за субтитры. Thank you very much
谢谢
The idea behind ocw is profound. By distributing knowledge to the whole world for free, MIT is paying tribute to the geniuses like faraday, curie, ramanujan etc... Who produced phenomenal works despite of not having the proper access to the knowledge they needed.
I love this teacher!! She's so funny, but in the driest way possible!! It's great! 😅
I want to ask a question not related to syllabus but a great tips Dr. Ana Bell used in this lecture, Lecture No 2(Branching and Iteration) and I have question in Time:39.48/43.30.... Here Dr. Ana used a great tips: She just select some sort of lines and deleted the "#" sign in a single moment.... I want to know how can I do it the same thing on Spyder.... Please comment to me... If you know please give me suggestion... Please Please.... (From INDIA)
This woman is so adorably awkward, nervous and brilliant.
@ChandravijayAgrawal
2 жыл бұрын
not really awkward but i think this is her first lecture on this topic
Who knew Darlene would be such a good professor
Transition from if-else to while loop tells how much i took the loops for granted .
She is second(I'm confused) best professor i ever got on MIT
thank you !
if course_grade == A: print("this teacher is amazing") elif course_grade in range (A, C+): print("This teacher is really good!") else: if course_grade
@blackjack-ks8zn
4 жыл бұрын
Else : If course_grade
@kasiviswanathboddeti9085
3 жыл бұрын
Syntax error For else: you shouldn't give a
Whene I've tried , the input part of the lecture ,,, The following message just showed up ( get ipython ().kernel.shell.run_line_magic('clear', ") Can anyone please help me !!!!! Otherwise, the lectures are perfect and Very well explained.
38:54 both codes ARE WORNG SHOULD BE for i in range(5, 11, 2 ): print(i) NOT LIKE : x = 0 for i in range(5, 11, 2 ): x += i print(x) I get output : 21 with that code for some reasons
Brilliant
Very nice information
So do we need spyder? because I'm using 3.6 and some of this doesn't seem to translate.
to improve examples e.g. for string print( "you_can", "show", "where_the_spaces_are_added", "!" * 3 ) the example code blocks could have a colored background or have a colored border
Why isn't "Type a number..." included in the output, as it is included within the quotation marks?
take = "Thank you" name = "Dr. Ana Bell" print (take + ", " + name)
@peterpace3379
4 жыл бұрын
(take, name)*
@geitekop507
4 жыл бұрын
print(take,","name,"!") is probably slightly better. ;-)
@blackjack-ks8zn
4 жыл бұрын
@@geitekop507 (take, " ", name, "!")
@kasiviswanathboddeti9085
3 жыл бұрын
print(take+",",name)
i have a question, how do you remove the first hashtags in a column with a shortcut?
I want to learn a lessong everyday if she is my teacher. I will never get tired or bored
the number you mention in parenthesis in for loop doesn't printed on the screen
Using which programming language can make CAD software?
thanks MIT
"b" is greater than "a" because __lt__ / __gt__ methods of the string class were made to convert the characters to ascii values and return the comparison of those values?
Hi people, anybody could give me a hand ? I'm trying to do the fingers exercises in the textbook for this course, and in chapter 3 there is one that says: 'Write a program that takes an integer enter by the user and prints two integers, root and pwr, such that 0 I'm really strugglin with the logic there and would gladly accept some help. Thank you
I am not getting that one at 12:26 I am doing this in Google colab, Is that the problem
everytime I hit print, nothing shows up in my console
Regarding range(stop,start,step) 40:30: Normally num-1, but in this case, we're going to the end minus "two". (num - 2). I came across a component of this topic on stackoverflow, where someone described the end of the range as "minus two", which left me puzzled, so I thought I'd post.
@mvisperas
3 жыл бұрын
Python always has the extra +1 whenever there is a range. This is different if you come from other programming languages but once you get used to it it will not bother you. Also true when slicing a string. For example: # 1 1 1 # 0 1 2 3 4 5 6 7 8 9 0 1 2 a = "hello, world!" # h e l l o , w o r l d ! b= a[1:8] print(b) # output # ello, w
@algemmegla9002
3 жыл бұрын
@@mvisperas In the case of range(5,11,2) From five up to but not including 11. It went 5...7...9 It stops at 9, and She says "...So we're going to the end MINUS ONE...." But actually it's going to the end, MINUS TWO. But I still agree with your comment. Normally, if it were range (5,11), with one hop as the default, it would be getting to the end (11) minus one. It was just a small thing, but thought I'd mention it. Yes, I see how you're thinking.
@algemmegla9002
3 жыл бұрын
Another example: Two hops. It goes to the end "minus two". for num in range(6,26,2): print(num, "", end="") 6 8 10 12 14 16 18 20 22 24 I also tried to index a range, but you have to change it to a list first because range is immutable. Range 20 up to, but not including, 50. Two hops. So up to the end "minus two". range_2 = list(range(20,50)) print(range_2[0:30:2],"", end="" ) [20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48]
@mvisperas
3 жыл бұрын
@@algemmegla9002 The end value is always the highest value without being equal to or exceeding the stop value - you can treat it as always less than. This statement is true whether the step value is 1, or 2, or 3, or whatever step value you choose. Thus if you do range(5, 11, 3) then the count is 5 ... 8. It won't do 11 as it is equal to the stop value.
@algemmegla9002
3 жыл бұрын
@@mvisperas I understand. Whatever is equal to the stop value gets ignored. I think we're both saying the same thing, but we're just wording our examples differently. As you mentioned in your example, you could say it stops at 11 because it is equal to the stop value, "and" you could also say it goes up to the end "minus two" (or 8) We're both saying the same thing. It's just different ways of explaining the concept.
5:00 the estar operator with strings
Could someone please explain what's the difference between the "+=" and "=+" operators?
@marco.nascimento
5 жыл бұрын
there is no such a sintax in python as "=+", only "+=". And "x += 1" is the same thing as "x = x + 1"
32:21.... y no n += 1?? also loving the Corse so far, did problem sets 0 and 1a before watching this, would love to go to MIT at some point in my life to get a Comp sci degree
@maar2001
Жыл бұрын
Bro where can I get the problem sets and where can I install the notes prof Ana made that she shows here?
for the maze game, " n=input("you are in a deep forest. **************** **************** Go left or right?")"under the while loop doesn't need any print command and it just repeats itself?
what was the version of python in these courses?
Whenever she shows the python codes on her PC's spyder, how she change from comment to code(vice versa) so quickly by dragging? is there any short cut for that functionality?
@Viruz256
6 жыл бұрын
If you press ctrl+1 in Spyder, all marked code changes to/from comment
@CrushOfSiel
4 жыл бұрын
@@Viruz256 Thank you! I was looking for this comment/answer!
For the while main_condition: while sub_condition: expression_a() break # This break always happens expression_b() # This will never execute expression_c() What is the point of having expression b if it will never execute?
I can't get enough my brain is finally feeling euphoric
28:10 While loop insted of if statement
19:40 three ways to make decitions
9:40 get input from user...every thing id a string, evento the numbers
did any one made expanding for the code of the game that puts sad face and many tables after entering right more than two times?
@semtex6412
3 жыл бұрын
𝚗 = 𝚒𝚗𝚙𝚞𝚝("𝚈𝚘𝚞 𝚊𝚛𝚎 𝚒𝚗 𝚝𝚑𝚎 𝙻𝚘𝚜𝚝 𝙵𝚘𝚛𝚎𝚜𝚝, 𝙶𝚘 𝚕𝚎𝚏𝚝 𝚘𝚛 𝚛𝚒𝚐𝚑𝚝?") 𝚠𝚑𝚒𝚕𝚎 𝚗 == "𝚛𝚒𝚐𝚑𝚝" 𝚘𝚛 𝚗 == "𝚁𝚒𝚐𝚑𝚝": 𝚛𝚒𝚐𝚑𝚝𝚜 = 𝟶 𝚏𝚘𝚛 𝚒 𝚒𝚗 𝚛𝚊𝚗𝚐𝚎 (𝟷): 𝚛𝚒𝚐𝚑𝚝𝚜 += 𝚒 𝚗 = 𝚒𝚗𝚙𝚞𝚝("𝚜𝚊𝚍𝚏𝚊𝚌𝚎, 𝚕𝚎𝚏𝚝 𝚘𝚛 𝚛𝚒𝚐𝚑𝚝?") 𝚗 = 𝚒𝚗𝚙𝚞𝚝('𝚏𝚕𝚒𝚙𝚜 𝚝𝚊𝚋𝚕𝚎𝚜, 𝚕𝚎𝚏𝚝 𝚘𝚛 𝚛𝚒𝚐𝚑𝚝?') 𝚠𝚑𝚒𝚕𝚎 𝚗 == "𝚛𝚒𝚐𝚑𝚝" 𝚘𝚛 𝚗 == "𝚁𝚒𝚐𝚑𝚝": 𝚗 = 𝚒𝚗𝚙𝚞𝚝('𝚏𝚕𝚒𝚙𝚜 𝚝𝚊𝚋𝚕𝚎𝚜, 𝚕𝚎𝚏𝚝 𝚘𝚛 𝚛𝚒𝚐𝚑𝚝?') 𝚙𝚛𝚒𝚗𝚝("\𝚗𝚈𝚘𝚞 𝚐𝚘𝚝 𝚘𝚞𝚝 𝚘𝚏 𝚝𝚑𝚎 𝙻𝚘𝚜𝚝 𝙵𝚘𝚛𝚎𝚜𝚝!\𝚗\𝚘/")
00:19:58 if/elif/else
do we have to use spyder ?
at 25:16 what's the use of the nested if? and when will it be used!
@maverick.3957
5 жыл бұрын
To check if a condition is true inside a condition. For example If 5 == 5: If 6 == 7: Print("Hello") First it will check if 5 is equal five which is true then it checks if 6 is equal to 7 which is false so it won't print "hello" it goes from up to down. Hope that helps 😊.
@Oliver-nb2iu
4 жыл бұрын
the nested if prints the quotient of x and y. however, you can't do this if y=0 as you will get a zero division error (if x=0 and y=0, 0/0 can't be evaluated)
As a mechanical engineer who is interested also in CS. These MIT courses are great way to learn
Thanks
how do you remove the # from multiple lines in spyder? whats the hotkey. theres probably also a hotkey to a add it. so comment/ uncomment selected lines. like at 39:48
@rizwanzeb5218
6 жыл бұрын
highlight the text and press ctrl+1
@abdullahchowdhury9589
3 жыл бұрын
@@rizwanzeb5218 Thank you very much... so happy to get my solution
on the 40th minute why i has the values 5 7 9 not 5 6 7 8 9 ????? please explain !!!
@ryankung3244
6 жыл бұрын
for range function, the parameters include start, end and steps. steps has default value of 1, therefore without explicitly specifying for the range function, you would get an iterator that output a sequence of values from 5,6,7,8,9,10 if it was range(5,11). However, since step was specified to be 2, each time the iterator will yield and output a new value equal to previous value + 2, which range(5, 11, 2) give you 5, 7, 9. Also since 11 will be greater and equal to 11, so 11 won't be part of the result for the range function.
Anaconda allows intereacitivty: IPython + Spyder (inspire on Matlab, (Matplotlib),+ support for other languages like ruby, R, Julia, Haskell ....etc. wow I am going to explore that tomorrow...