Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write the code in python. Part One: calculating offsets define the following variables (the first one is done for you) 3 diamond_offset = 0

Please write the code in python. image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Part One: calculating offsets define the following variables (the first one is done for you) 3 diamond_offset = 0 # holds the index of the first o club_offset = # holds the index of the first heart_offset = # holds the index of the first v spade_offset = # holds the index of the first Hint: do NOT use hard coded numbers other than the zero for diamonds. Come up with a mathematical expression to define the value (rather than saying heart_offset = 34) using the cards_per_suit variable. For example (this is not mathematically correct :) club_offset = diamond_offset * (cards_per_suit + 1) How would you test these offsets before moving on? Part Two: dealing from the deck define and test the following functions: first_card_in_deck(deck) which returns the first card in the deck last_card_in_deck(deck) returns the last card in the deck first_heart(deck) returns the first in the deck NOTES you can assume the following: the deck parameter will always be a set of cards in the A-K and 04 order Part Three: get_card Create the function get_card(deck, suit, rank) which returns the relevant card from the deck: suit will be one of rank will be a number 1 through 13 corresponding to (A, 2, 3 ..J,Q,K) In your code you need to calculate the appropriate index so you can do return deck[ calculated_index_value] For example to get the Qv you could use get_card like this: card = get_card(cards, 'V', 12) print(card) # it should be the Queen of Hearts! You MUST use the following restrictions: do not use any hard coded offsets (e.g. 23, 12) you can use the literals 0,1,2,3,4 only (don't use 13, use cards_per_suit) no hard coded cards (e.g return 'A') you can reference the variables defined in part one Part Four: using get_card write the following function: first_heart_v2 (deck) returns the first in the deck it MUST use get_card with the proper parameters Part One: calculating offsets define the following variables (the first one is done for you) 3 diamond_offset = 0 # holds the index of the first o club_offset = # holds the index of the first heart_offset = # holds the index of the first v spade_offset = # holds the index of the first Hint: do NOT use hard coded numbers other than the zero for diamonds. Come up with a mathematical expression to define the value (rather than saying heart_offset = 34) using the cards_per_suit variable. For example (this is not mathematically correct :) club_offset = diamond_offset * (cards_per_suit + 1) How would you test these offsets before moving on? Part Two: dealing from the deck define and test the following functions: first_card_in_deck(deck) which returns the first card in the deck last_card_in_deck(deck) returns the last card in the deck first_heart(deck) returns the first in the deck NOTES you can assume the following: the deck parameter will always be a set of cards in the A-K and 04 order Part Three: get_card Create the function get_card(deck, suit, rank) which returns the relevant card from the deck: suit will be one of rank will be a number 1 through 13 corresponding to (A, 2, 3 ..J,Q,K) In your code you need to calculate the appropriate index so you can do return deck[ calculated_index_value] For example to get the Qv you could use get_card like this: card = get_card(cards, 'V', 12) print(card) # it should be the Queen of Hearts! You MUST use the following restrictions: do not use any hard coded offsets (e.g. 23, 12) you can use the literals 0,1,2,3,4 only (don't use 13, use cards_per_suit) no hard coded cards (e.g return 'A') you can reference the variables defined in part one Part Four: using get_card write the following function: first_heart_v2 (deck) returns the first in the deck it MUST use get_card with the proper parameters

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_2

Step: 3

blur-text-image_3

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

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions