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

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

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

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

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

  5. Rewrite lines 2-5 so that x is assigned a value via a list comprehension on one line:
       x = 
    
    
  6. Approach for writing getData in words?

    
    
    
    
    
    
    
    
    
  7. Write getData

    
    
    
    
    
    
    
    
    
    
    

    SandwichBar

  8. Why good idea to return 0 and why some green?
    
    
    
    
    
    
  9. Why loop via an index in the SandwichBar APT? rather than values?
    
    
    
    
    

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

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

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

  13. 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?

  14. Pair (over how many dealt hands)?
    
    
    

  15. Two Pair (code and probability)
    
    
    
    
    

  16. Three of a Kind (code and probability)
    
    
    
    
    

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