Additional Python Resources

You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.

If you're having trouble with a particular concept or simply want to have access to more information, try one of the following links.

Documentation
  • Official Python 3 Documentation - "official"/technical explanation of what a particular function/operator does, examples of correct syntax, what the various libraries are, etc.
Textbooks/Tutorials
Debugging
  • Python Tutor - an excellent way to actually visualize how the interpreter actually reads and executes your code
  • DiffChecker - compares two sets of text and shows you which lines are different
  • Debugging in Python - steps you can take to try to debug your program
Software
Other Q&A
  • Stack Overflow - a large Q&A forum for programming concepts (not just Python). Try searching here before you post on the edX forum, and you may find that someone has already answered your question.
More Practice Problems
  • Python Challenge - a series of puzzles you can try to test your Python abilities
  • Project Euler - additional programming challenges you can try once your Python knowledge becomes stronger; problems are sorted by increasing difficulty
  • Coding Bat - problems you can solve within an online interpreter, specifically loops and lists
  • Codewars - improve your skills by training on real code challenges
  • Dictionaries - exercises on Python dicts
  • Classes and Object Oriented Programming - exercises on Python classes
Quiz Questions from 6.0001

Question 1 [3 points]. Assume that the variable x has been bound to a value of type int, and that the variable s has been bound to a value of type str. Write code that prints the value of x if that value is the same as the number of characters in s; otherwise it prints the string 'unequal'.
# For example:
# when x = 3 and s = 'abc'
# the code prints 3

# when x = 3 and s = 'abcde'
# the code prints 'unequal'

Question 2 [3 points]. Assume that s has been bound to a value of type str. Write code that prints the number of times a lowercase vowel (one of 'a', 'e', 'i', 'o' or 'u') appears in s.
# For example:
# when s = 'abcdefghi'
# the code prints 3

Question 3 [4 points]. Assume that x is a positive number bound to a value of type int. Write code that prints the largest power p (an integer) such that 2^p evenly divides x.
# For example:
# when x = 45
# the code prints 0

# when x = 48
# the code prints 4

Question 1 [3 points]. Implement the function that meets the specification below.
def mult(s1, s2):
    """
    s1 and s2 are non-empty strings of equal length
    If s1 and s2 can be converted to integers, (i.e. s1 and s2 are strings 
    containing only digits), returns the sum of pairwise products of every index. 
    The pairwise product of index i is the result of multiplying the digit in s1 
    and s2 that are at index i. If s1 or s2 cannot be converted to ints, return None.
    """
    # your code here

# For example:    
print(mult("3", "2"))  # prints 6
print(mult("123", "200"))  # prints 2, because 1*2 + 2*0 + 3*0 = 6
print(mult("12a3", "2.0.1"))  # prints None
print(mult("0123", "4321"))  # prints 10

Question 2 [3 points]. Implement the function that meets the specification below.
def binary_to_intlist(s):
    """
    s is a string made up of digits 0 and 1, representing a binary number.
    Converts s to its whole number representation in base 10, and returns each 
    digit of that whole number representation as an INTEGER element in a list 
    (in order from most significant to least significant). 
    """
    # your code here


# For example:
s = "0001101"
print(binary_to_intlist(s)) # prints the list [1, 3]
s = "100"
print(binary_to_intlist(s)) # prints the list [4]

Question 3 [4 points]. Implement the function that meets the specification below.
def coeffs_tup(x, y, z, total):
    """
    x, y, z are positive ints
    Returns the tuple of non-negative and integer coefficients a, b, c 
    (in this order) such that a*x+b*y+c*z = total where total is a 
    non-negative integer. If multiple values of a, b, c exist, choose any. 
    If no such coefficients exist, returns None.
    """
    # your code here


# For example:
print(coeffs_tup(1,2,3,1))  # prints (1, 0, 0) because 1*1+0*2+0*3 = 1
print(coeffs_tup(6,2,4,5))  # prints None
print(coeffs_tup(6,2,3,5))  # prints (0, 1, 1) because 0*6+1*2+1*3 = 5

Question 1 [3 points]. Implement the function that meets the specification below.
def apply(a, b, c, f):
    """ Assumes a, b, c are non-empty lists of ints and of the same length.
                f is a function that maps an int to an int.
        Returns a list A of the same length as a,b,c. For all i in 
        0...len(a)-1, A[i] is the result of applying f to the smallest of
        the values at index i of a, b, and c.
    """
    # your code here

# For example:    
a = [12, 3, 8]
b = [-11, 4, -7]
c = [3, 2, 2]
print(apply(a, b, c, abs))  # prints the list [11, 2, 7]

Question 2 [3 points]. Implement the function that meets the specification below.
def get_min(d):
    """ Assumes d is a non-empty dict mapping lower case letters to ints.
        Returns the value associated with the key in d that occurs the earliest in the alphabet.
    """
    # your code here

# For example:
d = {'x': 11, 'y': 3, 'c': 4}
print(get_min(d))  # prints 4

Question 3 [4 points]. Implement the function that meets the specification below.
def sum_floats(L):
    """ Assumes L is a list
        Returns the sum of all of the elements in L that can be cast to a float.
    """
    # your code here

# For example:
L = ['a', []]
print(sum_floats(L))  # prints 0

L = [1, '2.1', 'a', -1, '-1', [], (2,)]
print(sum_floats(L))  # prints 1.1