Compsci 101, Fall 2012, September 10

By entering your name/net-id below you indicate you are in class on September 10 to answer these questions and that you have answered them. Your name should not appear unless you are in class when answering these questions.
Name_________________   net-id _______   Name_________________   net-id _______


Name_________________   net-id _______   Name_________________   net-id _______

  1. What is the value of the Python expression "123"*2

    1. "246"

    2. "123123"

    3. error

  2. What is the value of the Python expression int("123")*2

    1. 246

    2. "246"

    3. "123123"

  3. The code below is intended to return the number of vowels in string parameter st: def vcount(st): v = 0 for letter in st: if EXPR: v = v + 1 return v Which of the following can replace EXPR to make the function work as intended (more than one can be correct).

    1. "aeiou".count(letter) > 0

    2. letter in "aeiou"

    3. "aeiou".find(letter) != -1

  4. Which expression correctly prints "even" if a number is even (more than one can be correct)

    1. if number % 2 == 0 : print "even"

    2. if number % 2 != 1 : print "even"

    3. if (number % 2 == 0) == True: print "even"