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 _______
- What is the value of the Python expression
"123"*2
- "246"
- "123123"
- error
- What is the value of the Python expression
int("123")*2
- 246
- "246"
- "123123"
- 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).
-
"aeiou".count(letter) > 0
-
letter in "aeiou"
-
"aeiou".find(letter) != -1
- Which expression correctly prints "even" if a number is even (more
than one can be correct)
-
if number % 2 == 0 : print "even"
-
if number % 2 != 1 : print "even"
-
if (number % 2 == 0) == True: print "even"