Answered You can hire a professional tutor to get the answer.

QUESTION

c = Card ('c', 7) there is no Error raised, everything seems fine.

"In the previous assignment "A Card Object", if your code asked for a new Card in this way:

c = Card ('c', 7)

there is no Error raised, everything seems fine. But then when you call the bjValue() method, or the __str__()

method, they both raise Errors and your program crashes. This is confusing and incorrect.

The __init__() method should not allow a Card object to be initialized with a 'c' for the rank and a 7 for the

suit. More generally, the __init__() method should raise an Error when any inappropriate values are sent into

its parameters. This will ensure that there will never be a meaningless Card object in any program ever.

For this assignment, you will add code to the __init__() method that raises a:

1) TypeError when the type of the first parameter is not an int.

2) TypeError when the type of the second parameter is not a string.

3) ValueError when the value of the first parameter is not in the range 1..13 inclusive.

4) ValueError when the value of the second parameter is not one of the strings in the set {'s', 'h', 'c', 'd'}

Hints∫

• Start this assignment by making any and all modifications suggested by my comments to your previous

assignment. If there is anything I wrote as feedback that you don't understand, please ask in the public

Discussion. Everything that I mention in the comment section of your Assignment in Canvas must result in

either a change to your source code or a post in the Discussion forum.

• Write the main program first. This program will attempt to create new Card objects with either an

inappropriate type or an inappropriate value. This main will have several try/except blocks, each one

containing an attempt to create a Card with an inappropriate value.

• The main program that tests your class Card must also attempt to create a new Card object with

appropriate†values in the parameters to the __init__() method. This attempt should, of course, not raise an

• The main program that tests your class Card must also attempt to create a new Card object with

appropriate†values in the parameters to the __init__() method. This attempt should, of course, not raise an error. It is critical that your main program contain many different tests, to see that bad Cards are not allowed

to be created and good Cards ARE allowed to be created.

• In order to make sure that the main program is a thorough test, keep all calls to bjValue() and __str__() in

there.

• Develop your code iteratively, but be sure to perform regression testing: Write and test code that

catches one of the four Errors at a time, but be sure that your main program performs all tests in one run. In

this way, you will make sure that newly written code that catches one of the Errors doesn't break your

solution that catches one of the previous Errors that you coded for.

• This assignment is asking you to change only the __init__() method in class Card, and the main() program

that tests all the functionality of class Card. Do not change any of the other methods in class Card unless

such a change was suggested in my comments to your submission of the previous "A Card Object"

assignment."

Test Code must be

try:

cardOne(#rank, suit)

except # Type or Value Error:

# print message here

Current Program:

(): , rank, suit):.rank = rank.suit = suitstring_temp = rank_var = ranks[.rank-]suit_var = suits.get(.suit)master_tuple = (rank_var, suit_var)card_name = string_temp card_name ) .rank ): .suit ):
Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question