Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Bartleby Related Questions Icon
Related questions
Question
please code in python
Please create a class called PlayingCard.
This class should have:
- An attribute, "rank" that takes a value of "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", or "A"
- An attribute, "suit" that takes a value of "♠" "♥" "♦" or "♣". (If you don't know how to make these characters you can cut and paste from this block)
- An init method that:
- Accepts as parameters a specific rank (as a string) and suit (as a string).
- Raise a TypeError with "Invalid rank!" or "Invalid suit!" when a rank or suit is not valid.
- The __str__ and __repr__ methods to display the cards correctly (as shown below in the examples)
2. Please create a class called Deck.
This class should have:
-
An attribute, "cards", that holds a list of PlayingCard objects.
-
An init method that:
- By default stores a full deck of 52 playing card (with proper numbers and suits) in the "cards" list. Each cards will be of the class PlayingCard above
- Allows the user to specify a specific suit of the 4 ("♠" "♥" "♦" or "♣"). In this case, the program should only populate the deck with the 13 cards of that suit.
- After the cards object is initialized, call the "shuffle_deck()" function (below).
-
A "shuffle_deck()" method that randomly changes the order of cards in the deck.
- Import the random library to 'shuffle' the deck: https://docs.python.org/3.9/library/random.html#random.shuffle
- Please import it at the top of your block instead of inside the class / methods.
-
A "deal_card(card_count)" method that:
- Removes the first card_count cards from the deck and returns them as a list.
- If the deck doesnt have the card_count number of cards left to deal, return the message Cannot deal <x> cards. The deck only has <y> cards left! (do not raise an exception or print inside the method).
Transcribed Image Text:Example:
>>> card1 = PlayingCard ("A", "4")
>>> print (card1)
A of 4
>>> card2 = PlayingCard ("15", "4")
<error stack >
TypeError: Invalid rank!
>>> card2 = PlayingCard ("10", "bunnies")
<error stack >
TypeError: Invalid suit!
>>> deck1 = Deck()
>>> print (deck1.cards)
[K of, A of ♥, 6 of 4, 7 of , 3 of 4, 6 of , Q of , 5 of+, 10 of, 2 of ♥, 8 of 4, 8 of , 4 of , 7 of, 3 of
+, K of +, 9 of , 4 of ♥, 10 of ♥, 10 of , A of , 9 of ♥, 7 of , 9 of +, 7 of +, 5 of , 3 of , 10 of , Q of ♥, J
of , 5 of ♥, K of ♥, K of
, 4 of 4, 5
of , 2 of, 4 of 4, 2 of
, 2 of 4, 8 of 4, Q of , 3 of 4, 6 of ♥, 6 of, A of +, A of, 3 of ♥, J of
, Q of 4, J of ♥, 8 of ♥, 9 of ]
>>> deck2 = Deck('')
>>> deck2.shuffle_deck()
>>> deck2.cards
[A of, 10 of , 3 of 4, 7 of , 5 of , 4 of 4, 8 of 4, 3 of 4, 9 of , Q of 4, 6 of 4, 2 of 4, K of 4]
>>> hand = deck2.deal_card (7)
>>> hand
[A of, 10 of 4, 3 of 4, 7 of 4, 5 of 4, 4 of 4, 8 of 4]
>>> deck2.deal_card(7)
'Cannot deal 7 cards. The deck only has 6 cards left!'
Expert Solution
Check MarkThis question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
bartleby
This is a popular solution
bartleby
Trending nowThis is a popular solution!
bartleby
Step by stepSolved in 4 steps with 2 images
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Java Programming Please do not change anything in Student class or Course class class John_Smith extends Student{ public John_Smith() { setFirstName("John"); setLastName("Smith"); setEmail("jsmith@jaguar.tamu.edu"); setGender("Male"); setPhoneNumber("(200)00-0000"); setJNumber("J0101459"); } class MyCourse extends Course { public MyCourse { class Course { private String courseNumber; private String courseName; private int creditHrs; public Course (String number, String name, int creditHrs){ this.courseNumber = number; this.courseName = name; this.creditHrs = creditHrs; } public String getNumber() { return courseNumber; } public String getName() { return courseName; } public int getCreditHrs() { return creditHrs; } public void setCourseNumber(String courseNumber) { this.courseNumber = courseNumber; } public void setCourseName(String...arrow_forwardsolution in python languagearrow_forwardpublic class VisitorPackage{// Declare data fields: an int named travelerID, // a String named destination, and // a double named totalCost.// Your code here... // Implement the default contructor.// Set the value of destination to N/A, and choose an // appropriate value for the other data fields,// Your code here... // Implement the overloaded constructor that passes new// values to all data fields.// Your code here... // Implement method getTotalCost to return the totalCost.// Your code here... // Implement method applyDiscount.//// This method applies a discount off of the total cost// of the tour. The way the discount is applied depends// on the kind of visitor.//// Child discount: the unit discount is subtracted ONCE// from the total cost of the tour.// Senior discount: the unit discount is subtracted TWICE// from the total cost of the tour.// Parameters:// - a char to indicate the kind of visitor// ('c' for child, 's' for senior)// - a double that indicates the amount of the...arrow_forward
- A field has access that is somewhere between public and private. static final Opackage Oprotectedarrow_forwardfast in pyth pleasearrow_forwardNumber Guessing Program using java: The player has to guess a number given in between a range. If the guessed number is right, the player wins else, loses. It also has the concept of limited attempts where the player has to guess the number within the limited attempts given. Note: It must incorporates the following OOP components: - Classes - Objects - Constructors - Class Variable - Object Methodarrow_forward
- Remove is a method that is defined.arrow_forwardclass Student: def __init__(self, id, fn, ln, dob, m='undefined'): self.id = id self.firstName = fn self.lastName = ln self.dateOfBirth = dob self.Major = m def set_id(self, newid): #This is known as setter self.id = newid def get_id(self): #This is known as a getter return self.id def set_fn(self, newfirstName): self.fn = newfirstName def get_fn(self): return self.fn def set_ln(self, newlastName): self.ln = newlastName def get_ln(self): return self.ln def set_dob(self, newdob): self.dob = newdob def get_dob(self): return self.dob def set_m(self, newMajor): self.m = newMajor def get_m(self): return self.m def print_student_info(self): print(f'{self.id} {self.firstName} {self.lastName} {self.dateOfBirth} {self.Major}')all_students = []id=100user_input = int(input("How many students: "))for x in range(user_input): firstName = input('Enter...arrow_forwardPython will give you high rating for correct help Easy Python Problem (see pic): Guides are available on the template below on what code to put: Template: ### Use this templateimport random class Card: def __init__(self, value, suite): self.value = value self.suite = suite def __str__(self): return f"{self.value} of {self.suite}" def __eq__(self, other): """Check if two cards are the same""" # -- YOUR CODE HERE -- class CardSet: def __init__(self): self.cards = [] def view(self): for card in self.cards: print(card) def add_cards(self, cards): """Add cards to your set""" # -- YOUR CODE HERE -- class Deck(CardSet): def __init__(self): """Initialize the 52-card set. Start from 1-11, then Jack, Queen, King, then by suite: clubs, spades, hearts, diamonds""" cards = [] # -- YOUR CODE HERE -- self.cards = cards def count_cards(self): """"Count the number...arrow_forward
- Python please. Starter code: from player import Playerdef does_player_1_win(p1_hand, p2_hand):#given both player-hands, does player 1 win? -- return True or Falsedef main():# Create players# Have the players play repeatedly until one wins enough timesmain() #you might need something hereclass Player: # player for Rock, Paper, Scissors# ADD constructor, init PRIVATE attributes# ADD method to get randomly-generated "hand" for player# ADD method to increment number of wins for player# ADD method to reset wins to 0# ADD getters & setters for attributesarrow_forwardPython Code please Point of Sale Write a program that will manage the point of sale in a store. Build the ItemToPurchase class with the following: Attributes item_name (string) item_price (int) item_quantity (int) Default constructor Initializes item's name = "none", item's price = 0, item's quantity = 0 Method print_item_cost() Example of print_item_cost() output:Bottled Water 10 @ 1ドル = 10ドル Extend the ItemToPurchase class to contain a new attribute. item_description (string) - Set to "none" in default constructor Implement the following method for the ItemToPurchase class. print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter. Example of print_item_description() output:Bottled Water: Deer Park, 12 oz. Build the ShoppingCart class with the following data attributes and related methods. Note: Some can be method stubs (empty methods) initially, to be completed in later steps. Parameterized constructor...arrow_forwardN-SIDED REGULAR POLYGON) In an n-sided regular polygon, all sides have the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). Design a class named RegularPolygon that contains: ▪ A private int data field named n that defines the number of sides in the polygon with default value 3. ▪ A private double data field named side that stores the length of the side with default value 1. A private double data field named x that defines the x-coordinate of the polygon's center with default value 0. ▪ A private double data field named y that defines the y-coordinate of the polygon's center with default value 0. A no-arg constructor that creates a regular polygon with default values. A constructor that creates a regular polygon with the specified number of sides and length of side, centered at (0, 0). A constructor that creates a regular polygon with the specified number of sides, length of side, and x- and y-coordinates. ▪ The accessor and...arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education