Define a class named Stock which represents the stock (hand) pile in the simplified Klondike Solitaire game. The Stock c
Posted: Thu May 05, 2022 1:10 pm
Define a class named Stock which represents the stock (hand) pile in the simplified Klondike Solitaire game. The Stock class contains the following: • A data field named items that defines the list of cards in the stock pile. Each card in the deck is represented by a unique number and these numbers range from 0 to n - 1 where n is the total number of cards. • A constructor/initializer that takes the total number of cards as a parameter and creates a Stock pile. The default value of the total number of cards is 0. If the total number of cards is bigger than 0, the initializer should insert integers from 0 to n - 1 where n is the total number of cards. The initializer should also use the random.shuffle() method to shuffle the numbers in the stock pile. • A method named push_list (self, values) which takes a Python List as a parameter and inserts all elements into the stock pile. • A method named is_empty(self) which returns True if the stock pile is empty, and False otherwise. • A method named size (self) which returns the number of items in the stock pile. • A method named __str__(self) which returns the string representation of the stock pile as shown in the examples below • A method named display (self) which displays the stock pile with one upturned card and n-1 downturned cards. You should print the cards starting with a letter "S" where "S" represents the "stock" pile. Note - keep a copy of your solution to this task because you will be extending it step by step in subsequent tasks. For example: Test Result random.seed (30) [1, 3, 5, 0, 2, 4] False s = Stock (6) print(s) 6 print(s.is_empty()) S: 1 * * *** print(s.size()) s.display() s = Stock() [2, 5, 1, 4, 3, 0] s.push_list([2, 5, 1, 4, 3, 0]) False print(s) 6 print(s.is_empty()) S: 2** *** print(s.size()) s.display() S = Stock() S: s.display() True print(s.is_empty())