Skip to content

Instantly share code, notes, and snippets.

@clintonyeb
Last active May 28, 2018 15:58
Show Gist options
  • Save clintonyeb/b18b7f35004618e02a74ee6086287a17 to your computer and use it in GitHub Desktop.
Save clintonyeb/b18b7f35004618e02a74ee6086287a17 to your computer and use it in GitHub Desktop.
Answering Ellis Questions
  1. "-the names of the ranks and the suits should be stored in class variables. See Module 5.6 "A Variable that belongs to the whole class"" >After reading that section (5.6),

What does this mean? I’m not understanding. Use class Card()?

Response:

This is an exampple of declaring a class variable:

class Name:
  firstName = "foo"
  
  def __init__(self):
    self.lastName = "bee"

In the example above: firstName is a class variable and lastName is an instance varibale.

What are class variables. Class variables are varibales of the class. Instance variables are variables of objects. In the example above: to access firstName, you can simply do this:

print(Name.firstName)

But to access lastName, you need to create an object(an instance) of the Class first.

name = Name()
print(name.lastName)

Why do we have class and instance variables: Class variables are usually the same for all objects you create from a class. But instance variables are different. Makes sense?

  1. This class makes a unique card with that has a unique black jack value, rank, and suit.

class Card():

Is this comment correct?

Response

I think the real problem with this assignment is that, you don't really know much about cards. So using it to learn a new concept makes it more challenging. On the otherside, this seems to be a wording issue.

Probably the comment will be more clear if it was

This class creates a card that has one value each from a set of ranks and a set of suits. That is, each card object has a rank and suit.

Got it?

  1. Copying from the assignment instructions: "attempt to create a new Card object with appropriate values" (-1) Your test code does not show that this class definition will work when trying to create a new Card object for a good, valid card. For example, will this code raise an Error?

validCard = Card(4,'d')

What does this mean?

Response:

He wants you to add a lot of test cases to show that your code works. Your tests must show the following: i. Invalid cards throw exceptions ii. Valid cards do not throw any exceptions.

  1. It is a good idea to put a blank line between the class definition and the test code.

What does this look like with example?

Response

Really simple:

Put line spaces between the real code and test code:

class Foo:
  def __init(self):
    self.name = 'ellis'
    
# See the blank line on top. Makes your code neat and easy to read.    
# Tests Cases
f - Foo()

Makes sense?

  1. -Also, your test code must show (in one run of the program) that all of the different types of Errors are raised when they should be raised. For example,

Do I use multiple Try: and else: and finally: to test codes that would show different types of errors?

Response

Use a single try except for each test case. When it fails, show it, else show smth else. Example:

# Test cases
try:
  c = Card(3, 'e')
  # The statement next will only be executed only and only if the code does not throw an error.
  print("creating a card with 3 and 'e' does not throw an error") 
 excerpt Exception as e:
  # The statement next will only be executed only and only if the code throws an error.
  print("Exception for creating card with invalid parameters 3 and 'e'")
  

Makes sense?

Have fun :)

@clintonyeb
Copy link
Author

Leave any problems here in the comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment