3. String Manipulation, Guess and Check, Approximations, Bisection

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 discusses string manipulation, guess-and-check algorithms, approximate solution methods, and bisection search.
License: Creative Commons BY-NC-SA
More information at ocw.mit.edu/terms
More courses at ocw.mit.edu

Пікірлер: 290

  • @vibhumaheshwari2826
    @vibhumaheshwari28263 жыл бұрын

    Dr. Bell really does deserve an applause. Nice to see that the students actually did that in the end of the lecture. An amazing lecture with such articulate explanation of concepts. Thank to MIT OCW and also to the course staff!

  • @Mahdi62822

    @Mahdi62822

    7 ай бұрын

    👍👍👍

  • @farmcat3198
    @farmcat3198 Жыл бұрын

    I love Dr. Bell's enthusiasm for this. Makes learning it so much more fun!

  • @user-fl7vs4ed6l
    @user-fl7vs4ed6l3 жыл бұрын

    0:01:54​ Strings 0:03:32 Strings indexing 0:05:34 (Coding) 0:06:49 Strings slicing 0:08:37 Strings slicing example 0:10:05 Strings slice inversly 0:11:18 ​Strings was fixed in memory 0:13:20​ For loops recap 0:16:31 Coding example : robot cheer leaders 0:18:00 Coding example : robot cheer leaders(Coding) 0:20:36 Coding example : robot cheer leaders 0:22:00 Coding example : robot cheer leaders 0:23:37 ​Guess and check cube root1.0 0:26:00 Guess and check cube root2.0 0:28:30​ Linear Search for cube root approximation 0:31:22 Linear Search for cube root approximation examples 0:32:53 Linear Search for cube root approximation of 10000 0:34:33 ​Linear Search preventing going to far 0:36:48 Bisection Search ​ 0:38:00​ Bisection Search @3rd iteration 0:39:52 Bisection Search summary 0:42:47 O(n) (Complexity)

  • @user-nm9fk7cb4b

    @user-nm9fk7cb4b

    2 жыл бұрын

    The true hero here

  • @calmdown1665

    @calmdown1665

    2 жыл бұрын

    Thanks a lot, it is handy.

  • @maar2001

    @maar2001

    Жыл бұрын

    I rlly appreciate Gigachads like you who make our life easy

  • @michaeladdisu8043

    @michaeladdisu8043

    Жыл бұрын

    tnx

  • @johnrubio5660
    @johnrubio56605 жыл бұрын

    Cannot exaggerate how helpful this content is. Thank you MIT OCW. I know hindsight is 20/20, but I wish I would’ve watched these videos (and the Walter Lewis videos) when I was in high school. I would’ve been so much more motivated to work hard and try to get into MIT.

  • @johnrubio5660

    @johnrubio5660

    5 жыл бұрын

    Edit: Walter Lewin

  • @stevemilo6935

    @stevemilo6935

    Ай бұрын

    You live a sad life of regret.

  • @user-nm9fk7cb4b
    @user-nm9fk7cb4b2 жыл бұрын

    This series of lectures and this lecturer are both so insightful that I often have to take long breaks between views because of the amount of complex and hidden/misunderstood information they make so accessible can make life overwhelmingly easy to understand Thank you Dr. Ana Bell, MIT and everyone involved with all of this! You are all amazing! (no angry text here :)

  • @user-ll7wq2ow8w
    @user-ll7wq2ow8w2 жыл бұрын

    first sorry about my miserable English. All I want to say is thank you very very much You gave me a new start and a new goal in my life with python.

  • @rustycanofbeans1009
    @rustycanofbeans1009 Жыл бұрын

    Im watching these lectures and practicing the course works from the website (the assignments and problem sets, also playing around with each thing I've learned). I've learned more in 3 days watching these than I have with a month of watching how-to tutorials (which is not surprising at all, just what I was trying before) and I am so glad I found this. I've made a very simple calculator that can add 2 numbers together that the user inputs! Very simple, but it's a victory to me! I'm starting college soon and majoring in computer science, so I can't wait to look back and see how far I've come. Really thanks to these kind people and this great teacher, I am understanding concepts that were constantly foreign to me no matter how much I tried to understand on my own. Although I haven't attended a class, I'll remember Dr. Bell as one of my favorite teachers because I have learned so much.

  • @12mohdyasirfaridi75
    @12mohdyasirfaridi756 жыл бұрын

    It was very useful. HUGE THANKS TO MIT.

  • @protoype123
    @protoype123 Жыл бұрын

    Thank you for these videos MIT and Professor Bell, I've learned so much from watching these videos and this has accelerated the career change I'm beginning now at 27. Much love, -Sam :)

  • @Helpmesubswithoutanyvideos

    @Helpmesubswithoutanyvideos

    Жыл бұрын

    I'm 27 years old and me to

  • @bighomietone195
    @bighomietone1956 жыл бұрын

    Ana Bell you’re the best 🙏🏽

  • @spyinsecret0075
    @spyinsecret00753 жыл бұрын

    She is an amazing teacher! Explain it so clearly and fun. Thank you so much!

  • @onemilee
    @onemilee3 жыл бұрын

    Hi guys. I'm going to thank the MIT team. Thank you, for these awsome courses.

  • @roshanshanbhag3489
    @roshanshanbhag34892 жыл бұрын

    In Metrology, the Approximate solution or Guess and check is analogous to Linear search and the bi-sectIon search that Dr. Bell used is called Binary search. We use it comprehensively to find the levels and timing parameters of an integrated circuit.

  • @aumkaarpranav8765
    @aumkaarpranav87652 жыл бұрын

    Wow! They clapped at the end. Can't remember ever being so much into the class that I end up clapping.

  • @mathlearning5331
    @mathlearning53314 жыл бұрын

    This video literally answered all of my remaining questions

  • @nasserghajarafshar762
    @nasserghajarafshar7625 жыл бұрын

    prof. Anna Bel your lectures are very helpful thanks

  • @bkpickell
    @bkpickell3 жыл бұрын

    Thank you for these courses. I took programming 17 years ago and wanted to brush up and learn Python. Since that seems to be the go to language now. I learned on VB. I've written a couple programs in VB for my current employer to connect to, manipulate, and retrieve data from a database. Mainly to make my job easier. LOL... I thought I would try and learn to do it in a more current language. Granted I have to get through this 6.0001 course first so I can get to 6.0002 where I need to be for database programming. I'm just hoping to learn something I didn't know. So far it's just refresher, which is fine. I already know pretty much everything being discussed. It's just slightly different syntax such as the double =, that's not a thing in VB. Or the single quote vs double quote. Yeah that's not a thing in VB either double quote only for strings.

  • @alienlan
    @alienlan4 жыл бұрын

    I absolutely love these courses! Learning so much! Both lecturers I've seen are outstanding, and much appreciation to everyone involved in this amazing gift to mankind! I do have one, small suggestion, though. It would be great to leave the camera on the slides for longer periods of time. In a classroom, as I'm taking notes, I am focused more on the slides and what the teacher is saying, than on how they look (even though these teachers are very pleasant to watch). Because there is so much video of the instructors, it leads to a lot of pausing on slides and interrupting their wonderful lectures. :(

  • @ghaithghazi6748

    @ghaithghazi6748

    4 жыл бұрын

    Brother you can find the slide on the course website alongside with the code and most importantly there are some challenging assignments.....I highly recommend you to check those.

  • @sp4557
    @sp45573 жыл бұрын

    cube = float(input("Enter a no whose cube root is to be calculated: ")) epsilon = 0.01 num_guesses = 0 if cube > 1: low = 0 high = cube guess = (low + high)/2.0 while abs(guess**3 - cube) >= epsilon: if guess**3 low = guess else: high = guess guess = (low + high)/2.0 num_guesses += 1 elif 0 low = cube high = 1 guess = (low + high)/2.0 while abs(guess**3 - cube) >= epsilon: if guess**3 low = guess else: high = guess guess = (low + high)/2.0 num_guesses += 1 elif -1 low = cube high = 1 guess = (abs(low) + high)/2.0 while abs(guess**3 - abs(cube)) >= epsilon: if guess**3 low = guess else: high = guess guess = (low + high)/2.0 num_guesses += 1 else: low = cube high = 0 guess = (abs(low) + high)/2.0 while abs(guess**3 - abs(cube)) >= epsilon: if guess**3 low = guess else: high = guess guess = (low + high)/2.0 num_guesses += 1 print('num_guesses = ', num_guesses) if cube guess = -guess print(guess, "is close to the cube root of", cube) I guess this covers all possible cases?

  • @canpeanionut

    @canpeanionut

    Жыл бұрын

    Thanks a bunch! I'm a MD trying to learn python. This helped a lot, couldn't really wrap my head around the class challenges.

  • @jasmeetxxx9

    @jasmeetxxx9

    Жыл бұрын

    appreciated.

  • @Haganenno121

    @Haganenno121

    2 ай бұрын

    I suppose it should be >=1, otherwise else: applies

  • @markmahathey690
    @markmahathey6904 жыл бұрын

    this was a good lecture. I hope I watch them all.

  • @PedramNG
    @PedramNG3 жыл бұрын

    The final algorithm that she explained is actually called Successive Approximation which there is also circuits for that which is called Successive Approximation Register (SAR) Analog to Digital Converter (ADC). Looking at these algorithms being in both computer science and electronic engineering is so cool.

  • @bobanmilisavljevic7857

    @bobanmilisavljevic7857

    4 ай бұрын

    You get a little extra bang for your buck at MIT 💪🥳

  • @itsjose666
    @itsjose6663 жыл бұрын

    Amazing content. Thank you MIT.❤

  • @gxa5986
    @gxa59863 жыл бұрын

    Thanks for sharing knowledge in free Actually Approximations were a headache for me which u guys solved.

  • @harmainarif4302
    @harmainarif43025 жыл бұрын

    thnks alot prof Ana Bell ,,its very helpful for me

  • @qcislander
    @qcislander5 жыл бұрын

    Love it. Dr. Bell, I hope you're still at this: you do it *really* well, and as I've watched from the first lecture, you're losing (or taming?) what seems to be a little stage-fright. I've never lost mine, but I did tame it enough to teach by interactive lectures way back when. Good onya. :-) One question: the "bisection" method seems just like (electronics engineering technology 35 years ago) what we called "successive approximation by halves"... and we did it with logic-gate constructs and not code... but is that the same idea?

  • @jasonbarr5176

    @jasonbarr5176

    4 жыл бұрын

    Yes, it's the same idea. In fact, I just Googled it out of curiosity (electronics are not my area, though I'd like to get more into it) and several articles on successive approximation by halves make reference to binary search (another name for bisection search) explicitly.

  • @jalapenohiway
    @jalapenohiway4 жыл бұрын

    I really love this course and had to donate! Between MIT OCW & Free Code Camp, I'm definitely learning a lot of valuable information! Thank you! You guys are absolutely amazing!

  • @Billyxiao

    @Billyxiao

    2 жыл бұрын

    Yes definitely this is more informative

  • @leonardoagostini6743
    @leonardoagostini67435 жыл бұрын

    Code at 35:33 does not work for negative cubes. Here some changes in order to let it work also for negative numbers. Hope it will be useful :). ___________________________________________________________________________________ cube = 27 epsilon = 0.01 guess = 0.0 increment = 0.0001 num_guesses = 0 while abs(guess**3 - cube) >= epsilon and abs(guess**3) = epsilon: print('Failed on cube root of', cube) else: print(guess, 'is close to the cube root of', cube)

  • @george6709

    @george6709

    2 жыл бұрын

    #this works too 👍🏾 cube = float(input(" enter your preferred number: ")) guess = 0.0 epsilon = 0.1 increment = 0.01 if cube >= 1: while abs(guess**3 - cube) >= epsilon: guess += increment print(guess, "is close to the cube root of", cube) else: while abs(guess**3 + cube) >= epsilon: guess += increment print(-guess, "is close to the cube root of", cube)

  • @Underdoge_

    @Underdoge_

    Жыл бұрын

    nice!

  • @akbarrauf2741
    @akbarrauf27417 жыл бұрын

    thank you ,mit

  • @88bjjmichael

    @88bjjmichael

    7 жыл бұрын

    akbar rauf and Dr Ana Bell

  • @pranaymishra9696

    @pranaymishra9696

    3 жыл бұрын

    @@88bjjmichael f

  • @kuuz1134
    @kuuz11344 жыл бұрын

    college drop out learning python for free from MIT, who would have ever thought...

  • @paulochikwekwe7862

    @paulochikwekwe7862

    4 жыл бұрын

    kuuz am here in disbelief too

  • @PotatoSauc3

    @PotatoSauc3

    3 жыл бұрын

    Here!

  • @demolazer

    @demolazer

    3 жыл бұрын

    Same here. I dropped out years into a CS degree ten years ago. Am learning it all from MIT now. Better lecturers than I ever had.

  • @superfreiheit1

    @superfreiheit1

    3 жыл бұрын

    There also good python courses outside

  • @655tern

    @655tern

    2 жыл бұрын

    Same here

  • @brainstormingsharing1309
    @brainstormingsharing13093 жыл бұрын

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

  • @aymensekhri2133
    @aymensekhri21334 жыл бұрын

    thanks a lot Dr. Ana Bell

  • @semtex6412

    @semtex6412

    3 жыл бұрын

    lol. thank MIT. she's being paid to teach whilst being filmed. nothing glorious there. if anything, she stutters so much it feels like her mind keeps wandering off somewhere. Prof. Eric Grimson was way better!

  • @Unknowledgeable1
    @Unknowledgeable12 жыл бұрын

    13:00 On for loops #pre 14:20 #14:39 It seems that you don't need to use the word range() when u are binding characters to the iteration variable 16:27 more complicated example of assigning characters to iteration variable #pre 19:32 explanation of 'in' keyword 19:50 20:14

  • @daizhao4874
    @daizhao48742 жыл бұрын

    What a helpful and interesting class!

  • @thomasgarman6353
    @thomasgarman63533 жыл бұрын

    picking up python, I know absolutely nothing but I am 3 lectures in. Anybody else actually following along with the whole series and doing the problems the course gives ?

  • @goswamivibhor

    @goswamivibhor

    2 жыл бұрын

    You may check on internet by searching the topics names and basic problems regarding them

  • @jamaldangelo4227

    @jamaldangelo4227

    Жыл бұрын

    Im the same, how did it go pal?

  • @thomasgarman6353

    @thomasgarman6353

    Жыл бұрын

    @@jamaldangelo4227 oh wow it’s been a year, it went so well lol, I am much more confident in my programming abilities and have done a lot of really cool projects. Coding has been a very rewarding journey

  • @jamaldangelo4227

    @jamaldangelo4227

    Жыл бұрын

    @@thomasgarman6353 Good to hear pal, I'm currently just starting now, trying to find a coding job in the next 6-9 months...

  • @TenMinuteKQL
    @TenMinuteKQL9 ай бұрын

    Great session! Thank you for contributing to the coding community.

  • @felzebub1762
    @felzebub17623 жыл бұрын

    Excellent videos!! Thanks MIT

  • @yukeyang5735
    @yukeyang57355 жыл бұрын

    bisection,very insightful

  • @mikhailskalyga9386
    @mikhailskalyga93863 жыл бұрын

    Great lecture, thank you!

  • @matthiastakele
    @matthiastakele4 жыл бұрын

    43:51 She meant to say it only works for cubes greater than or equal to 1

  • @TrangNguyen-cs6wv
    @TrangNguyen-cs6wv6 жыл бұрын

    21:58 Start of Basic Algorithms

  • @gachle
    @gachle Жыл бұрын

    Dammnnn what an experience should be studying at MIT!!!

  • @FaizAther
    @FaizAther6 жыл бұрын

    # cube root calc cube = input("Please input a number: ") cube = int(cube) for guess in range(abs(cube) + 1): if guess**3 == abs(cube): if cube > 0: print("The cube root of", cube, "is", guess) break elif cube guess = -guess print("The cube root of", cube, "is", guess) break if guess**3 > abs(cube): print("Not a perfect cube")

  • @niteshmodi5468
    @niteshmodi54683 жыл бұрын

    I am sending a packet of thanks to mit for this clear explanation And sorry I can't afford a Google product so only thank you

  • @bucksera475
    @bucksera475 Жыл бұрын

    God bless you.

  • @davidanamunda6766
    @davidanamunda67663 жыл бұрын

    this is very helpful

  • @ashley_harwood
    @ashley_harwood6 жыл бұрын

    # This might be of help to someone as I had trouble following along due to this misconception # Assign the string "MIT" to variable "i" i = 'MIT' # Print the elements of variable "i" starting from index 0 and ending at index 3 but not including index 3 - "[0:3]" print(i[0:3]) # When working with an index remember that it starts at 0 "[0:]" # when specifying where you would like to end the index "[:3]" it's up to the index value 3 but not including it # So in this example - "M" is located at index 0 # "I" is located at index 1 # "T" is located at index 2 # >>> MIT # If we were to print the elements of variable "i" at index "[0:2]" it would be print(i[0:2]) # >>> MI # "M" is located at index 0 # "I" is located at index 1 # "T" is located at index 2 # Rember it's up to the index value 2 but not including it

  • @longvo1426

    @longvo1426

    4 жыл бұрын

    You're a saviour.

  • @kshitijsingh5728
    @kshitijsingh57283 жыл бұрын

    Why aren't we getting cube root of 27 and 8120601 in form of x.xx as we always increment guess by second decimal place.

  • @nicktucker3437
    @nicktucker34378 ай бұрын

    37:00 that's exactly how one should play the clock game on the price is right.

  • @dsee777
    @dsee7776 ай бұрын

    At 10:05, a typo in screen slides ...evaluates to "hgfedbca", should be "hgfedcba".

  • @kumarjalaj1222
    @kumarjalaj12226 жыл бұрын

    nice lecture

  • @jimkennedy4509
    @jimkennedy4509 Жыл бұрын

    Great. I was hoping she would use Newton-Raphson or secant method for the cube root calculation.

  • @ir8487
    @ir84872 жыл бұрын

    Are there any recommended videos to watch on KZread following this course to build more upon Python knowledge? Thanks!

  • @Mokhtartba
    @Mokhtartba7 ай бұрын

    Her Voice is Good and the Explaining is perfect ! thanks M-I-T the game of guess was Fun :D .

  • @jh0720
    @jh07205 жыл бұрын

    13:21 loop variable that iterates over a collection, not a set?

  • @uetianeinsteins204
    @uetianeinsteins2044 жыл бұрын

    nice work by DR. ANNA BELL and MIT as well..

  • @pfever
    @pfever6 жыл бұрын

    Correct me if I'm wrong but in 43:50 when the professor says the code works only for positive cubes, she makes an example of 0.5 not working, but that is the positive cube of 0.79... So I guess the correct statement to make is that this algorithm works only for positive cubes "bigger or equal to 1".

  • @wenjucui9272

    @wenjucui9272

    5 жыл бұрын

    My understanding is that her code does not work for 2 situations: 1) negative cubes 2) x

  • @Adam-bq2us

    @Adam-bq2us

    5 жыл бұрын

    @@wenjucui9272 I know she said it is a simple if statement but I can't figure it out. What did you do to make it work? My thought is: if cube guess = -guess

  • @wenjucui9272

    @wenjucui9272

    5 жыл бұрын

    @@Adam-bq2us I considered two situations: if cube >=0: low=0 high=cube guess = (high + low)/2.0 then do the while loop comparing epsilon; else: low=cube high=0 guess = (high + low)/2.0 then do the while loop again to compare with epsilon. hope this helps. I haven't worked out the between 0, 1 situation.

  • @bkpickell

    @bkpickell

    3 жыл бұрын

    @@Adam-bq2us Before running the code listed just state If cube is >= 1 then {insert code from course} that's all that is needed

  • @rohineeroy7860

    @rohineeroy7860

    2 жыл бұрын

    @@bkpickell can you please give the full solution? I cannot find any

  • @tsuba666
    @tsuba666 Жыл бұрын

    38:00 the fact Sophie chosed 76 makes me wonder if she had an inkling as to what the teacher was aiming at. I mean a middle guess +1 is the hardest to find in a bisectional search. So either Sophie was lucky, or she's a sly fox >:)

  • @Mahdi62822

    @Mahdi62822

    7 ай бұрын

    lol right

  • @theviper8652
    @theviper86526 жыл бұрын

    when should we start doing those given assissgnment

  • @eduardorodriguez1897
    @eduardorodriguez18973 жыл бұрын

    What does she mean with we can use for loops to iterate ANY SEQUENCE OF VALUES?? Im learning coding from scratch and some terms and concepts are quite sneaky to comprenhend, dont be to harsh pleas, and thanks

  • @kasiviswanathboddeti9085
    @kasiviswanathboddeti90853 жыл бұрын

    Cube root simple guess. Why does that code keeps running?

  • @Caspian917
    @Caspian9175 ай бұрын

    Here's what I have for bisection search that accounts for negative numbers and abs (numbers) cube = -0.027 epsilon = 0.0001 num_guesses = 0 if cube >= 1: low = 0 high = cube elif cube >= 0 and cube low = cube high = 1 elif cube -1: low = -1 high = cube else: low = cube high = 0 if abs(cube) == 1: guess = cube else: guess = (high + low) / 2.0 while abs(guess**3 - cube) >= epsilon: if guess**3 low = guess else: high = guess guess = (high + low) / 2.0 num_guesses += 1 print('num_guess is', num_guesses) print(guess, 'is close to cube root of', cube)

  • @joesparlin4268
    @joesparlin42685 жыл бұрын

    Thanks

  • @utkarshmishra1302
    @utkarshmishra13022 жыл бұрын

    My teacher in INDIA taught me in same way, iam studing in class 11th feeling too good after watching this, that i have same access to learning as any other brilliant student have 💛💛😇😇🇮🇳🇺🇸

  • @iitasperiant6102

    @iitasperiant6102

    Жыл бұрын

    Hello bro I am indian

  • @curiousss4960
    @curiousss49605 жыл бұрын

    Who edited this? Every time she's pointing and talking about something on the board the camera is on her for some reason. Really bad practice.

  • @ashen1970

    @ashen1970

    5 жыл бұрын

    yup that is so dumb edition

  • @shubhankarsingh4065
    @shubhankarsingh40653 жыл бұрын

    18:00 nice example

  • @Rolandas3K
    @Rolandas3K Жыл бұрын

    Nice tutorial and lesson. Just a small note, IMHO, on ~35:00 Anna made a small "mistake" when added "and guess

  • @oiciruamlau4795
    @oiciruamlau47954 жыл бұрын

    What I get from the approximation algorithm is that it will only give you an answer if the difference between guess**3 and cube is equal to epsilon, if it manages to jump above epsilon, guess will increase in value until it is

  • @Divyansh-Tiwari

    @Divyansh-Tiwari

    4 жыл бұрын

    cube = 10000 epsilon = 0.1 guess = 0.0 increment = 0.01 num_guesses= 0 while abs(guess**3 -cube) >= epsilon: # and guess = epsilon and guess**3 > cube: # new inserted line print("sorry the the epsilon jumped up and the cube is not found the last guess was",c) # new inserted line break # new inserted line print('num_guesses=', num_guesses) if abs(guess**3 -cube) >= epsilon: print('Failed on cube root of', cube) else: print(guess, 'is close to the cube root of', cube)

  • @DatascienceConcepts
    @DatascienceConcepts4 жыл бұрын

    Very useful

  • @likesurfs
    @likesurfs3 жыл бұрын

    Can anybody explain me in Assignment 1 part C of the downpayment problem(The one where we calculate ideal monthly savings rate) Why am I getting an Infinite loop. I followed all instructions. Help would be appreciated. annual_salary = float(input("Please enter your yearly salary: ")) monthly = annual_salary/12 portion_saved = 0.0 cost = float(input("Please enter the cost of your dream home: ")) down_payment = 0.25*cost semi = float(input("Decimal rate of increase of semi annual salary: ")) low = 0.0 high = 1.0 x = (low+high)/2 r = float(input("Rate of interest yearly for savings:")) current_savings = 0.0 month = 0 while abs(current_savings - down_payment)>= 100.0 : portion_saved = x*monthly while month

  • @Underdoge_
    @Underdoge_ Жыл бұрын

    0:34:43 I would add 'and abs(guess**3)

  • @khico5463
    @khico54635 жыл бұрын

    my teacher is beautyfull

  • @zvisnjicyt
    @zvisnjicyt2 жыл бұрын

    MIT one and only!👍🇷🇸

  • @carterash2588
    @carterash25886 жыл бұрын

    when the robots are cheering, can you index word[1,3] in the for loop? for char in word[1,3]:

  • @Phagocytosis

    @Phagocytosis

    4 жыл бұрын

    The index notation uses colons, not commas, so it would be word[1:3]. But other than that, yes, you could do that, and then you would loop over only the characters that are in that substring. So if the original string word is "ROBOTS", the substring word[1:3] would be "OB".

  • @debkumarbiswas9927
    @debkumarbiswas99272 жыл бұрын

    Guess & Check: cube = -27 # only guess the first natural number for which guess**3 >= cube for guess in range(abs(cube)+1): if guess**3 >= abs(cube): break # return perfect cube, if exists if guess**3 == abs(cube): if cube print("Cube root of " + str(cube) + " is " + str(-guess)) else: print("Cube root of " + str(cube) + " is " + str(guess)) # if there exists no perfect cube else: print(str(cube) + " is not a perfect cube")

  • @venom_21332
    @venom_213323 жыл бұрын

    thanks!

  • @-Mohamed_bayan
    @-Mohamed_bayan3 жыл бұрын

    27:39 what if the cube is not perfect and negative? ,

  • @cerberusrap
    @cerberusrap2 ай бұрын

    An "all possible inputs" approach for cheer loop (Eric taught me 😐): an_letters = "aefhilmnorsxAEFHILMNORSX" word = input("I will cheer for you!. Enter a word: ") times = int(input("Enthusiasm level (1 - 10): ")) if times > 10: while times > 10: times = int(input("Please ensure an enthusiasm level between 1-10 ")) for char in word: if char == ' ': continue if char in an_letters: print("Give me an " + char + "! " + char) else: print("Give me a " + char + "! " + char) print("What does that spell?") print((word + "!!! ")*times)

  • @diegogimbernat9253
    @diegogimbernat92536 жыл бұрын

    I love her.

  • @abhilashc2965
    @abhilashc29654 жыл бұрын

    @21:20 Clean and peaceful

  • @anubhabganguly7579
    @anubhabganguly75793 жыл бұрын

    Very helpful resources 💙

  • @santanacasas1
    @santanacasas16 жыл бұрын

    What is the answer of cube = 27 on the exercise. I rewrote the code on the IDE but the execution never ended, why? Help, please

  • @AnilKumar-un6jn

    @AnilKumar-un6jn

    6 жыл бұрын

    LOL Happens, Your increment is may be too small, so that it is maybe taking too much time.

  • @androtech7885

    @androtech7885

    4 жыл бұрын

    Dude the same thing happened for me. I never got an answer even after changing the 27 to some other value.

  • @DSimonJones

    @DSimonJones

    3 жыл бұрын

    Try.......If you copied and pasted from slides the last three lines may be indented. they should start at beginning of each line.

  • @alexandrugheorghe5610
    @alexandrugheorghe56108 ай бұрын

    13:29 0,1,2,3 since it starts from 0

  • @lukem8420
    @lukem8420 Жыл бұрын

    I’ve watched this twice, and it’s still hard as hell for me to grasp

  • @frantzwidnyjoseph3571
    @frantzwidnyjoseph35713 жыл бұрын

    The idea of creating something to cheer oneself up is just funny

  • @joybreegaming8781
    @joybreegaming878110 ай бұрын

    38:50 why was my first thought before she even explained the method to choose e as my number

  • @15997359
    @159973592 ай бұрын

    S[4:1:-2] evaluates to "eca"

  • @daveyjones9699
    @daveyjones96994 жыл бұрын

    Is there a typo at 6:56? s[: : -1] -> "hgfed'BC'a" doesn't make sense, unless it's supposed to be "...cba"

  • @mussabsaleem7625

    @mussabsaleem7625

    4 жыл бұрын

    Yes it is cba or BCa

  • @aghaaslam9575

    @aghaaslam9575

    3 жыл бұрын

    true, there is a mistake. this comment should have a lot of like !!!

  • @rohineeroy7860
    @rohineeroy78602 жыл бұрын

    someone please give me the bisection solution for cube = 0.5 and cube < 0 🙏🙏

  • @TheTruthFadeswithTime28
    @TheTruthFadeswithTime286 жыл бұрын

    How do you do a bisection search for a cuberoot when x is a decimal? I can’t be find an answer anywhere.

  • @rysknet

    @rysknet

    5 жыл бұрын

    if abs(cube) high = 1.0 This worked for me. Logic is that if 1 is less than 0 we just need to change the higher bound and a good number to change it to is 1 because the answer won't be greater than one anyway.

  • @temtamyassine2292

    @temtamyassine2292

    3 жыл бұрын

    @@rysknet if cube high = 1 low = guess And even with that you may have an infinite loop because doing comparison for float numbers is tricky, see the style guide pdf

  • @neelnagarajan514
    @neelnagarajan5144 жыл бұрын

    when I try to run the code at 32:07, my cell just says In[*] instead if In[a number] and the cell doesn't even run. Anyone know what's going on? Note: the rest of my notebook until this point is running perfectly.

  • @simersingh9239

    @simersingh9239

    4 жыл бұрын

    go to the kernel tab, click on interrupt. then try again

  • @idens13
    @idens1310 ай бұрын

    cube = 27 epsilon = 0.01 num_guess = 0 low = 0 high = cube guess = (high + low) / 2 while abs(guess**3 - cube) >= epsilon: print(abs(guess**3 - cube), guess, (guess ** 3)) if guess**3 low = guess else: high = guess guess = (high + low) / 2 num_guess += 1 print('num_guess =', num_guess) print(guess, 'is close to cube root of', cube)

  • @rakuou2578
    @rakuou25786 ай бұрын

    In the approximate way of finding cube root codes: the guesses is increasing by guess += increment. I may think the output of guess should be multiply of increment, why the final output is something like .999999999998

  • @darkpikachu_.
    @darkpikachu_.4 жыл бұрын

    can''t believe sophie didn't pick 69

  • @bee_irl

    @bee_irl

    3 жыл бұрын

    I can't believe Bell pronounces gif "jif"

  • @user-nm9fk7cb4b

    @user-nm9fk7cb4b

    2 жыл бұрын

    Creep

  • @gaiuszeno1331
    @gaiuszeno13315 жыл бұрын

    The professor mentioned that a previously assigned string stays in memory after the variable is reassigned. Does this mean the programmer has to free memory allocates to the string manually?

  • @eymongaming7217

    @eymongaming7217

    5 жыл бұрын

    Not in Python, since there is the garbage collector.

  • @DB-sf1hy

    @DB-sf1hy

    4 жыл бұрын

    Eymon Gaming which language does need to free memory manually?

  • @doanduytrung651
    @doanduytrung6516 жыл бұрын

    Could you please tell me which programming environment python do you use in the lecture?

  • @ghostprime2993

    @ghostprime2993

    6 жыл бұрын

    they use anaconda but you can use geany also. I prefer geany

  • @rayyanhussain2356

    @rayyanhussain2356

    6 жыл бұрын

    It's called Spyder, it comes with anaconda. Link to website --> anaconda.org/anaconda/spyder

  • @leb-chip3268
    @leb-chip32683 жыл бұрын

    Can someone help me out - surely the code at 29:55 is wrong? The While loop should not run because the condition is not true i.e. guess**3 - cube is NOT greater than or equal to 0.1. Rather 0x0x0 - 27 is LESS than 0.1? So surely the While loop would not run in the first place?

  • @TTYounga

    @TTYounga

    3 жыл бұрын

    The abs is a function that returns the absolute value of the argument, so in this case abs(-27) returns 27, which in turn is greater than (or equal) to 0.01 (epsilon)

  • 3 жыл бұрын

    39:37 bisection search code

  • @saucymiri
    @saucymiri3 ай бұрын

    Are these videos outdated or are they still a good place to start learning Python?

  • @nup_pun
    @nup_pun7 жыл бұрын

    In lecture 3 slide there is a small typo; s[::-1] evaluates to "hgfedcba"

  • @mussabsaleem7625
    @mussabsaleem76254 жыл бұрын

    at 24:50 why is there a *+1* in range of that for loop? To make the loop go till *8* instead of stopping at *7*?

  • @Phagocytosis

    @Phagocytosis

    4 жыл бұрын

    Yes, that is right. Since the second parameter of the range function, the end point, is taken as a non-inclusive endpoint, if you want the loop to go over that number as well you need to add one. So to make it include 8 rather than stop after 7, just as you said.

  • @mussabsaleem7625

    @mussabsaleem7625

    4 жыл бұрын

    @@Phagocytosis ty :D

  • @Phagocytosis

    @Phagocytosis

    4 жыл бұрын

    @@mussabsaleem7625 No problem!