Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using python, please include docstring so I can get an understading. For a CMPT 145 course so keep the code simple please. . Card. average

Using python, please include docstring so I can get an understading.

For a CMPT 145 course so keep the code simple please.

image text in transcribedimage text in transcribed
. Card. average (list_of_cards) Takes a list of cards, and returns the average (float) value of this given list of cards. average = Card . average (["5D", "10H", "Q5", "8C", "JH"]) # Will compute the average for: 5, 10, 12, 8, 11 print (average ) # outputs: 9.2 Testing Write a test script that tests your implementation of the ADT, and ensures that all operations are correct Think about the same kinds of issues: . White-box test cases. . Black-box test cases. . Boundary test cases, and test case equivalence classes. . Test coverage, and degrees of testing. . Unit vs. Integration testing. Running your test script on your correct ADT should report no errors, and should display nothing except the message '*** Test script completed ***'. What to Hand In . A Python program named a4q4. py containing the ADT operations (new and modified). . A Python script named a4q4_testing . py containing your test script.Question 4 (12 points): Purpose: To implement an ADT from a requirements specification. Degree of Difficulty: Moderate A pack of playing cards has four suits. 'H'. "D' 'S'. and 'C, (Hearts, Diamonds. Spades and Clubs) and a value 1 through 13 making a total of 52 cards. The following symbols map to the following values: A=1, 2=2. 3=3. 4-4. 5-5. 6-6, 7-7, 8-8, 9-9, 10-10, J-11, Q-12, K-13 (with A being the Ace. J being the Jack, Q being the Queen and K being the King). The suit a card belongs to does not affect its value, so, 2H and 25 both have the value of 2. On the other hand, OH has a higher value of 12 compared to AH that has a value of 1 You are required to design and implement an ADT named card. A card is a data structure that carries out some operations on a pack of cards. Each card itself will be stored as a string, with a numeric value preceding a letter (ex: JD' for the jack of diamonds, '5H" being the 5 of hearts, etc). The card ADT has 6 operations: . Card. create () Creates and returns a list of all possible cards that can be drawn from the 52 card playing deck. That is, all possible combinations of the suits of cards ['H' 'D' 'S'. 'C'l and the values 1 through 13 (but using A as 1, J as 11, Q as 12, K as 13). print ( Card . create () ) # ["AH", "2H", "3H", "4H", "5H", "6H", "7H", "8H", "9H" , "10H", " JH", "QH", "KH", . . .] # Repeated for the 3 other suits (D, S, C) . Card. deal (num_cards, num_players, deck) Randomly deals a number of cards to a number of play- ers from the given deck (list of card strings). When a card is drawn, it is removed from the deck. deal() returns each player's hand as a list of lists. It is up to you to decide what happens if the deck runs out of cards before all players have been dealt all of their cards. cards_dealt = Card . deal (5, 3, deck) print (cards_dealt) # [["5D" , "10H", "Qs", "8C", " JH"] , # [" JC" , "2H" , "8D" , "AS", "90"] , ["7H" , "6H" , "9H" , "105" , "8H"] ] . . Card. value (card) Takes in the string of a card, and returns its integer value. Remember, its suit does not affect its value. Also remember that A=1, J=11, Q=12, K=13. For example. Card.value("KS") returns 13. and Card.value(*4D") returns 4. . Card. highest (list_of_cards) Takes a list of cards, and returns the the card string with the highest value. For example: highest_card = Card . highest (["5D", "10H", "QS", "SC", "JH"]) print (highest_card) # outputs : "Qs" . Card. lowest (list_of_cards) Takes a list of cards, and returns the string with the lowest value. For example: lowest_card = Card . lowest (["5D", "10H", "QS", "8C", "JH"]) print (lowest_card) # outputs: "5D"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions