In-Class Questions and Video Solutions

Lecture 3

  1. String Manipulations

    What does the code below print?

    s = "6.00 is 6.0001 and 6.0002"
    new_str = ""
    new_str += s[-1]
    new_str += s[0]
    new_str += s[4::30] 
    new_str += s[13:10:-1]
    print(new_str)
    

     260000  close
     26100  close
     26 100  check
     nothing, it will give an error  close
     6.00 is 6.0001 and 6.0002  close
    Check Show Solution

  2. For Loops with Strings

    How many times will the code below print “common letter”?

    s1 = "mit u rock"
    s2 = "i rule mit"
    if len(s1) == len(s2):
     for char1 in s1:
     for char2 in s2:
     if char1 == char2:
     print("common letter")
     break
    

     0  close
     2  close
     4  close
     5  close
     6  close
     7  check
     8  close
     10  close
    Check Show Solution

Course Info
Learning Resource Types
assignment Problem Sets
notes Lecture Notes
theaters Lecture Videos
assignment_turned_in Programming Assignments with Examples