Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I am confused with Dictionaries with Python and I need help with my assignment. All work is done within http://www.codeskulptor.org Please make sure all

Hello,

I am confused with Dictionaries with Python and I need help with my assignment. All work is done within "http://www.codeskulptor.org"

Please make sure all work is done with "http://www.codeskulptor.org" *****Please make sure all the code works with codeskulptor.org**** ( PYTHON 2.7)

Below is my Dictionaries Assignment:

A dictionary is a way to link pieces of information together so that they can be accessed using the format dict[key] = value. This is similar to a list, however in a list the key is the index and in a dictionary the key can be any type of value. A dictionary is created in the format dict = {key1:value1, key2:value2, ...}. See the CodeSkulptor Docs Types & Operations, Dictionaries to see additional methods and commands.

For this assignment:

Create a dictionary called card_values where the keys are the ranks of playing cards stored as strings ("A", "2", "3", ...) and the values are the values according to the game Rummy. In Rummy, 2's are worth 20 points, aces are worth 15, face cards and 10's are worth 10 and all other cards are worth 5 points.

Write a function called new_hand which takes the number of cards as a parameter and returns a random hand (a list of ranks, ignoring suits for now). For example, new_hand(4) might return ["3","K","8","A"].

Write a function called calc_value which takes in a hand and returns the total value of the hand, using the dictionary.

Create a hand by calling the new_hand function.

Find the value of the hand by calling the calc_value function.

Print the hand and its value.

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

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago