Compsci 101, Fall 2012, September 5
By entering your name/net-id below you indicate you are in class on
September 5 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 _______
- In Python, which of the following is an expression
for how many meters an object falls due to gravity on Earth
when the initial velocity is
velo
(m/sec) and
the object falls for sec
seconds. More than one
may be correct.
-
velo*sec + 4.9*sec*sec
-
9.8*(sec**2)/2 + sec*velo
-
Math.gravity(velo,sec)
- What is the value of the Python expression below?
"ba"*3 + "na"*2
- error
- bababanana
- bananabananabanana
- bananabanana
- WHatis the value of the Python expression below?
"ba" + 3 * "na" + 2
- error
- bababanana
- bananabananabanana
- bananabanana
- What is the value of the Python 2.7 expression
16 / 7 + 16 % 3
- 2
- 3
- 4
- other
- In Python what is printed when the loop below
executes:
for s in "duke":
print s*3,
- ddduuukkkeee
- dukedukeduke
- error
- Which best characterizes the function
days
below:
def days(month):
if month == "January":
return 31
elif month == "March":
return 31
elif month == "May":
return 31
elif month == "July":
return 31
elif month == "August":
return 31
elif month == "October":
return 31
elif month == "December":
return 31
elif month == "February":
return 28
else:
return 30
- It correctly returns the number of days in a month
represented by parameter
month
, but it's wrong for February
in a leap year.
- Each of the
elif
occurrences could be replaced by if
and the code word work the same way
- The function returns 30 for the call
days("january")