ill thumb up do your best
python3
import random
class CardDeck:
class Card:
def __init__(self, value):
self.value = value
self.next = None
def __repr__(self):
return "{}".format(self.value)
def __init__(self):
self.top = None
def shuffle(self):
card_list = 4 * [x for x in range(2, 12)] + 12 * [10]
random.shuffle(card_list)
self.top = None
for card in card_list:
new_card = self.Card(card)
new_card.next = self.top
self.top = new_card
def __repr__(self):
curr = self.top
out = ""
card_list = []
while curr is not None:
card_list.append(str(curr.value))
curr = curr.next
return " ".join(card_list)
def draw(self):
"""
>>> import random; random.seed(1)
>>> deck = CardDeck()
>>> deck.shuffle()
>>> deck.draw()
10
>>> deck.draw()
8
>>> deck.draw()
10
>>> deck.draw()
6
>>> deck
8 9 3 10 2 10 6 5 8 10 3 10 9 2 10 9 6 10 5 5 2 6 8 7 2 4 10 4 11
10 3 10 10 5 7 10 10 11 7 7 3 11 10 4 4 9 11 10
"""
return None
if __name__ == "__main__":
import doctest
doctest.testmod()
import doctest
import random
class CardDeck:
class Card:
def __init__(self, value):
self.value = value
self.next = None
def __repr__(self):
return "{}".format(self.value)
def __init__(self):
self.top = None
def shuffle(self):
card_list = 4 * [x for x in range(2, 12)] + 12 * [10]
random.shuffle(card_list)
self.top = None
for card in card_list:
new_card = self.Card(card)
new_card.next = self.top
self.top = new_card
def __repr__(self):
curr = self.top
out = ""
card_list = []
while curr is not None:
card_list.append(str(curr.value))
curr = curr.next
return " ".join(card_list)
def draw(self):
"""
>>> import random; random.seed(1)
>>> deck = CardDeck()
>>> deck.shuffle()
>>> deck.draw()
10
>>> deck.draw()
8
>>> deck.draw()
10
>>> deck.draw()
6
>>> deck
8 9 3 10 2 10 6 5 8 10 3 10 9 2 10 9 6 10 5 5 2 6 8 7 2 4 10 4 11 10 3 10 10 5 7 10 10 11 7 7 3 11 10 4 4 9 11 10
"""
# get top card
top=self.top
# move to next card
self.top=self.top.next
return top
if __name__ == "__main__":
doctest.testmod()
Screenshot:


ill thumb up do your best python3 import random class CardDeck: class Card: def __init__(self, value):...
Now, create a Deck class that consists of 52 cards (each card is an instance of class Card) by filling in the template below. Represent the suit of cards as a string: "Spades", "Diamonds", "Hearts", "clubs" and the rank of cards as a single character or integer: 2, 3, 4, 5, 6, 7, 8, 9, 10, "J", class Deck: def init (self): pass # Your code here. def draw (self): Returns the card at the top of the deck, and...
How do you do this? class Event: """A new calendar event.""" def __init__(self, start_time: int, end_time: int, event_name: str) -> None: """Initialize a new event that starts at start_time, ends at end_time, and is named name. Precondition: 0 <= start_time < end_time <= 23 >>> e = Event(12, 13, 'Lunch') >>> e.start_time 12 >>> e.end_time 13 >>> e.name 'Lunch' """ self.start_time = start_time self.end_time = end_time self.name = event_name def __str__(self) -> str: """Return a string representation of this...
COMPLETE THE _CONSTRUCT() AND CONSTRUCTTREE() FUNCTIONS class expressionTree: class treeNode: def __init__(self, value, lchild, rchild): self.value, self.lchild, self.rchild = value, lchild, rchild def __init__(self): self.treeRoot = None #utility functions for constructTree def mask(self, s): nestLevel = 0 masked = list(s) for i in range(len(s)): if s[i]==")": nestLevel -=1 elif s[i]=="(": nestLevel += 1 if nestLevel>0 and not (s[i]=="(" and nestLevel==1): masked[i]=" " return "".join(masked) def isNumber(self, expr): mys=s.strip() if len(mys)==0 or not isinstance(mys, str): print("type mismatch error: isNumber")...
11p
Python Language
Read the following code for oofraction. import oofraction class OOFraction: def main(): fl = oofraction.o0Fraction( 2, 5) f2 = oofraction.o0Fraction ( 1, 3) f3 = f1 + f2 print (str(3)) main() def __init__(self, Num, Den): self.mNum = Num self.mDen = Den return def_add_(self,other): num = self.mNumother.mDen + other.mNum*self.mDen den = self.mDen*other.mDen f = OOFraction(num,den) return f 1. Write the output below. def_str_(self): s = str( self.mNum )+"/" + str( self.mDen) returns 2. Write a class called wholeNum...
Python question class LinkNode: def __init__(self,value,nxt=None): assert isinstance(nxt, LinkNode) or nxt is None self.value = value self.next = nxt Question 2.1. Empty Node In some cases in it convenient to have a notion of an empty linked list. Usually it means that the linked list does not have any elements in it. In order to keep things simple (for now) we will assume that the list is empty, if it has a single node and its value is None. Add...
python
. Write the function poker_hand that takes a list of exactly five distinct Card objects as an argument, analyzes the list, and returns one of the following strings that describes the hand: "Four of a kind' (four cards of the same rank) 'Full house' (three cards of one rank, and two cards of a different rank) . 'Flush' (five cards of the same suit) 'Three of a kind' (exactly three cards of the same rank) • 'One pair' (at...
class BinaryTree:
def __init__(self, data, left=None, right=None):
self.__data = data
self.__left = left
self.__right = right
def insert_left(self, new_data):
if self.__left == None:
self.__left = BinaryTree(new_data)
else:
t = BinaryTree(new_data, left=self.__left)
self.__left = t
def insert_right(self, new_data):
if self.__right == None:
self.__right = BinaryTree(new_data)
else:
t = BinaryTree(new_data, right=self.__right)
self.__right = t
def get_left(self):
return self.__left
def get_right(self):
return self.__right
def set_data(self, data):
self.__data = data
def get_data(self):
return self.__data
def set_left(self, left):
self.__left = left
def set_right(self, right):
self.__right...
I have to write a program where the program prints a deck of
cards. instead of having your regular suits and numbers the program
will use a value for a number, id will be either rock, paper, or
scissors, and the coin will be heads or tails. print example: 2 of
rock heads. If the user is enters 1 the program will print out 30
of the print example and arrange them by there values. if the user
enters 2...
Player Class Represents a participant in the game of
blackjack.
Must meet the following requirements: Stores the individual
cards that are dealt (i.e. cannot just store the sum of the cards,
you need to track which specific cards you receive) Provided
methods: decide_hit(self): decides whether hit or stand by randomly
selecting one of the two options.
Parameters: None
Returns: True to indicate a hit, False to indicate a stand
Must implement the following methods:
Hi!! i just need help with...
9p
This is for Python I need help.
Pet #pet.py mName mAge class Pet: + __init__(name, age) + getName + getAge0 def init (self, name, age): self.mName = name self.mAge = age Dog Cat def getName(self): return self.mName mSize mColor + __init__(name, age,size) + getSize() + momCommento + getDog Years() +_init__(name, age,color) + getColor + pretty Factor + getCatYears def getAge(self): return self.mAge #dog.py import pet #cat.py import pet class Dog (pet. Pet): class Cat (pet. Pet): def init (self,...