Comp 115 Final Exam Study Guide

Test on May 8-9 (two full days to complete the exam)

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.

A recap video is now available here.

In addition to all concepts from Test 4,

Classes

Practice Problems

  1. 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 asks the user for a few cards, prints them back and prints the associated Blackjack value of all cares together.
  2. Write a function getShuffledDeck that creates a randomly shuffled full deck of cards (no jokers). To do this, you may want to have a look at the shuffle function in the random library
  3. 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
  4. 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.
  5. Draw a stack diagram of main just before it starts printing.