Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment Starter code Python programming Thank you! This lab will test your ability to declare lists, initialize lists, and compute lists using function calls. Due

image text in transcribedAssignment
image text in transcribedStarter code
Python programming
Thank you!
This lab will test your ability to declare lists, initialize lists, and compute lists using function calls. Due 11:59pm, Friday, March. 1t, 2019 QUESTION: There are a variety of games possible with a deck of cards. For example, a deck of cards has four different suits, i.e. spades (+), clubs (), diamonds ), hearts(), and thirteern values for each suit. These decks of cards all have different number of categories and each category usually has the same number of cards. Now write a function that uses list eemprehensien and for loop to create a deck of cards. Each element in the list will be a card, which is represented by a list containing the category as a string and the value as an int. First, write a function called deck) that generates the deck of cards that contains all category in the categories list and each category should contain number_of_cards_per_cat cards starting from 1 to number of cards_per_cat as described in the doc string. You must follow the order of cards as listed in categories variable. If umber_of_cards per_cat is smaller than or equal to zero, then return an empty list. Then write another function random_shuffle0 that receives the list representing the deck of cards and return a randomly shuffled list but preserves the order of the categories. Your shuffled list should not be the same as the one generated from deck0 Finally, write a function reverse0 that receives the list representing the deck of cards returns the list in reverse order TO DO: Download the file lab5.py, complete the functions inside according to their descriptions and upload your version of lab5.py to MarkUs. IMPORTANT: Do not change the file name or function names. Do not use input0 or print0. Your file should not contain any additional lines of code outside the function definitions. Some example test cases are included in the docstrings. HINTS: You can generate N random integers between 1 and Max with the following lines of code: First, you should import the random library: import random then: random.sample(range (1, Max), N) return a list of N random numbers between 1 and Max import random def deck (categories, num of cards per cat): (list, int) -> list Given a list of strings representation as category names and an integer category, example, with "spades "hearts", 2, [ "spades",2, "hearts", 1, "hearts, 2] indicating the number of cards in one return a deck of cards as a list. For return a list of list: spades,1, where 1 and 2 are the index of the cards >> deck ("spades "hearts"], 2) [ [" spades",1, "spades",2, "hearts 1, "hearts, 211 >> deck ("spades, "hearts ,-5) def random shuffle(lst): (list) -> list Receives a deck of cards and returns a randomly ordered list containing all of the same elements. order of the categories. See below and "d" stay in the same order as shuffled The returned list should preserve the console outputs as an example, where s" the input and only the numbers are >> randomshuffle(["s,1,["s",21, def reverse (lst): (list) -> list Receives a list and returns a reverse ordered list containing all of the same elements. ["hearts", 1], ["hearts", 2]]) 2, "spades", 1]] >> reverse("spades", 1,[ " spades",2, [["hearts", 2], "hearts", 1, "spades

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

Database And Expert Systems Applications 19th International Conference Dexa 2008 Turin Italy September 2008 Proceedings Lncs 5181

Authors: Sourav S. Bhowmick ,Josef Kung ,Roland Wagner

2008th Edition

3540856536, 978-3540856535

More Books

Students also viewed these Databases questions