Compsci 06/101, Spring 2012, Lab 3
By entering your name/net-id below you indicate you are present for Lab 3
to answer these questions and that you were part of
the process that resulted in answers being turned in.
Name: ______________ Net id: _____________ || Name: ______________ Net id: _____________
Name: ______________ Net id: _____________ || Name: ______________ Net id: _____________
Vocabulary
- What do you think the name of the string method is that returns the
lower case version of a string?
- The function
max returns the maximal value of a string
as well as a list. What is max("science") and why?
- What is the value of
reversed(sorted([5,4,1,2,8])) and
why?
- What is the value of
sorted(lst).index(min(lst)) for
any list lst? Why? What's the value if
min is replaced by max?
- Why is the value of
str.endswith(str[-3:]) True?
- When is the value of
st.upper().endswith(st) True?
(Provide a specific example of when it's true and try to generalize)
- The
in operator determines if its left operand occurs
in its right operand and returns a boolean value. This means
'a' in 'stranger' evaluates to True. What
is the value of 5 in [1,2,3,4]?
- Explain when the value of
st[0:2] in st is False?
(Provide a specific example of when it's true and try to generalize)
- Explain when the value of
st[0:2]*2 in st is True?
(Provide a specific example of when it's true and try to generalize)
- When is the value of
lst.count(lst[0]) the same
as the value of len(lst) for a list lst?
(Provide a specific example of when it's true and try to generalize)
APT Acronym
Write a brief, English description of how to solve the APT.
- Complete the code statement below.
words =
- Write the for-loop here:
- Write loop to create the acronym:
acro = ""
return acro
Bagels APT
- Is it possible/ok to use
elif in solution A?
- Explain why the three
if statements in solution
A
can be replaced by the last statement, e.g., so that the only statement
in the loop body is bagels = bagels + i + (i/12)
- Explain why solution B isn't as general as solution
A?
- Explain why
int isn't a good name for the variable
used
in the for-loop of solution B.
- Explain why
int isn't a good name for the variable
used
in the for-loop of solution B.