Python Programming: An Introduction to Computer Science, 3rd Ed.
Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
bartleby

Concept explainers

bartleby

Videos

Question
Book Icon
Chapter 11, Problem 15PE
Program Plan Intro

Program to deal out a sequence of cards

Program plan:

  • Import the required packages
  • A class named “Deck” is defined.
  • The function named “__init__()” is defined and inside it,
    • Declare and initialize the required array variables.
    • A loop is initialized to derive the values of cards.
      • Calculate the store the values in “x” and “y”.
      • Then the cards are appended in the array named “cardSpecs[]”.
    • Declare another array named “cards[]”.
    • A loop is initialized to append the cards in the array named “cards[]”.
  • The function named “__shuffle()” is defined and inside it,
    • Declare and initialize the required array variables.
    • A loop is initialized to store the shuffled cards.
      • Calculate the store the values in “x”.
      • Then the cards are appended in a new array named “newList[]”.
      • Remove that value of x from previous array named “cards[]”.
      • Return the value stored in newList.
  • The function named “shuffle()” is defined and inside it,
    • Assign the value stored in “self.__shuffle()” to “self.cards”.
  • The function named “dealCards()” is defined and inside it,
    • Return the value stored in first “self.cards.pop()”.
  • The function named “cardsLeft()” is defined and inside it,
    • Return the length of the value stored in “self.cards()”.
  • In the “main()” function,
    • Declare the variable “deck” that creates the class named “Deck()”
    • The function named “shuffle()” is called.
    • A loop is initialized to store the shuffled cards.
      • Print the output value that returned from “deck.dealCard()”.
  • Call the function “main()”.

Blurred answer
Students have asked these similar questions
pet shop wants to give a discount to its clients if they buy one or more pets and at least five other items. The discount is equal to 20 percent of the cost of the other items, but not the pets.Use a class Item to describe an item, with any needed methods and a constructor public Item(double price, boolean isPet, int quantity)An invoice holds a collection of Item objects; use an array list to store them. In the Invoice class, implement methods public void add(Item anItem)public double getDiscount()Write a program that prompts a cashier to enter each price and quantity, and then a Y for a pet or N for another item. Use a price of –1 as a sentinel. In the loop, call the add method; after the loop, call the getDiscount method and display the returned value.
Can you implement the Student class using the concepts of encapsulation? A solution is placed in the "solution" section to help you, but we would suggest you try to solve it on your own first. You are given a Student class in the editor. Your task is to add two fields: ● String name ● String rollNumber and provide getter/setters for these fields: ● getName ● setName ● getRollNumber ● setRollNumber Implement this class according to the rules of encapsulation. Input # Checking all fields and getters/setters Output # Expecting perfectly defined fields and getter/setters. There is no need to add constructors in this class.
Write a class that represents a player in a game. The player should have a name, password,experience points, an inventory array of four strings, and a location x,y. Your class shouldhave mutator and accessor methods for all variables. For example: setName(), getName(). Itshould have a suitable display method. Mutators and accessors should be public but allvariables should be private. To implement get inventory, use string * getInv(); Use the scoperesolution operator to implement larger methods such as display(). Use in class methods forshorter methods such as setName(), getName(). (in C++)Example:void setName(string name){this->name = name;}string *getInv();...string* player::getInv(){return inventory;}Note that in the above method setName “this->” is required for disambiguation. If writtenvoid setName(string n){name = n;}“this->” is not required.Write a test program that creates three players and displays them.Example Output:This program generates three player objects and…
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
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
9.1: What is an Array? - Processing Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=NptnmWvkbTw;License: Standard Youtube License