Compsci 06/101, Spring 2012, Lab 5

By entering your name/net-id below you indicate you are present for Lab 5 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

  1. What is the value of x after line 5 executes?
    
    
    

  2. What is the value of amount after line 5 executes?
    
    
    

  3. What is the value of y after line 6 executes?
    
    
    

  4. What value is stored in result by the call shown?
    
    
    

  5. Rewrite lines 2-5 so that x is assigned a value via a list comprehension on one line:
       x = 
    
    

  6. First write one or two sentences describing the approach you'll take in writing the function: what functions will you call, what will you loop over, what will you return?
    
    
    
    
    
    

  7. Write the function
       def getAges(data):
    
    
    
    
    
    
    


    SandwichBar

  8. Why loop via an index in the SandwichBar APT?
    
    
    

  9. Why will you need to call split in the loop above, e.g., on order[index]? (in words)
    
    
    

  10. First, what's the purpose (in words) of the boolean variable ok shown above?
    
    
    

  11. After the loop above executes, what should be returned if the value of ok is True?
    
    
    

  12. The APT specifies that -1 is returned if no sandwhich can be made, when will that happen and where does the return statement go?
    
    


    Poker


    What odds did you calculate for each of the following poker hands?

  13. Pair (over how many dealt hands)?
    
    
    

  14. Two Pair (code and probability)
    
    
    
    
    

  15. Three of a Kind (code and probability)
    
    
    
    
    

  16. Full House (code and probability)
    
    
    
  17. Challenge Flush (code and probability)