Lecture 2 - Exercises

2A - Data Types

  1. What is the result of each of the following function calls?
    1. type(7.0)
    2. type("7.0")
    3. type(7)
    4. float(7)
    5. str(7.0)
    6. type(3+4)
  2. If you pass a positive float argument to the int function, which of the following does it do?

2B - Variables and Assignment

  1. Which of the following does not print the same thing as the others?

    Program A:

    a = 14
    b = 3
    print(a, b)

    Program B:

    a = 3
    b = 14
    print(14, 3)

    Program C:

    a = 14
    b = a
    print(a, b)

    Program D:

    a = 3
    b = 14
    print(14, a)
  2. Consider the following program:

    a = 5
    b = 5
    a = 6
    b = 7

    After this program executes, what values do a and b hold?

  3. What does the following program print?

    x = 3.0
    m = 2.0
    b = -4.0
    y = m * x + b
    print(y)