Compsci 101, Fall 2012, Lab 4
By entering your name/net-id below you indicate you are present for Lab 4
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: _____________
Test Practice
- What is the type/value of
x
after line 5 executes?
- What is the type/value of
amount
after line 5 executes?
- What is the type/value of
y
after line 6 executes?
- What value is stored in
result
by the call shown? Type?
- Rewrite lines 2-5 so that
x
is assigned a value via
a list comprehension on one line:
x =
Approach for writing getData
in words?
Write getData
SandwichBar
- Why good idea to return 0 and why some green?
- Why loop via an index in the SandwichBar APT? rather than values?
- Why will you need to call split in the loop above, e.g., on
order[index]
? (in words)
- First, what's the purpose (in words) of the boolean variable
ok
shown above?
- After the loop above executes, what should be returned if
the value of
ok
is True? Why?
- The APT specifies that -1 is returned if no sandwich can be
made, when will that happen and where does the return statement
go? Why?
Poker
What odds did you calculate for each of the following poker hands?
- Pair (over how many dealt hands)?
- Two Pair (code and probability)
- Three of a Kind (code and probability)
- Full House (code and probability)
- Challenge Flush (code and probability)