Comp 115 Test 5 Study Guide

Test on December 3-4 (depending on your lab section) 3:30-4:20 in lab

I tried my best to list the topics for the exam but I may have forgotten one or two. Your default assumption should be that if I covered it in class, it is fair game for the exam.

I will add practice problems as I find new interesting questions, so come back to this page every few days, more practice problems may have appeared.

Reminder: you are allowed to bring one one-sided, handwritten cheat sheet. I will collect the cheat sheet with the exam, you can pick it back in my office on Friday, December 6.

In addition to all concepts from Test 4,

Basic Design

Classes

Practice Problems

  1. Finish any lab exercises that you did not have time to complete during lab time. Remember, I added a whole page of exercise for the week of Fall break during which we did not have lab.
  2. Implement a class to represent a playing card. Your class should have the following methods:
    • __ init __ (self, rank, suit) rank is an int in the range 1-13 indicating the ranks ace-king and suit is a single character "d " "c " "h " or "s" indicating the suit (diamonds, clubs, hearts, or spades). Initialize the corresponding variables in the object.
    • getRank(self) Returns the rank of the card.
    • getSuit (self) Returns the suit of the card.
    • value(self) Returns the Blackjack value of a card. Ace counts as 1, face cards count as 10.
    • __ str __ (self) Returns a string that names the card. For example, "Ace of Spades". You can use numbers for the number cards, but use the English name for the face cards.
    Test your card class with a program that prints out n randomly generated cards and the associated Blackjack value where n is a number supplied by the user.
  3. Write a function getShuffledDeck that creates a randomly shuffled full deck of cards (no jokers).
  4. Write a function getTwoHands that uses the previous function to get a randomly shuffled deck of cards, gets two hands of 4 cards from that deck (use slices) and returns those two hands
  5. Write a function main that uses the previous function to get two random hands and, over four lines, prints the contents of each hand in English and prints the total Blackjack value or each hand.
  6. Draw a stack diagram of main just before it starts printing.