Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class Starburst that represents a pack of Starburst pieces. Each Starburst object, will keep track of one data attribute, a list of the

Write a class Starburst that represents a pack of Starburst pieces. Each Starburst object, will
keep track of one data attribute, a list of the pieces of candy contained in the pack. For the sake of brevity, each
piece of candy will be represented by a single uppercase letter, representing its color. (No data validation is
required). Your class definition should include 3 methods ( init__,, eat). WRITE YOUR
SOLUTION ON THE BACK OF THIS PAGE. Implementation details follow.
Creating and displaying objects:
(constructor)- accepts one optional argument, a list of strings representing the colors of the pieces
of candy. If no argument is given, these pieces should default to ['R','Y','B','O','G','P'].
(No data validation is required).
-?(())repr?? returns a string representing the Starburst object as indicated in the examples below.
>>>s Starburst(['R','Y','B'])??# list of colors passed as argument
>>>s
Starburst(['R','Y','B'])
>>>s= Starburst()??# no argument, use default
>>>s
Starburst(['R','Y','B','O','G','P'])
The eat method allows you to consume one or more pieces from the Starburst pack. Details:
accepts one optional argument, the number of pieces to eat. If no argument is provided, this defaults to 1
piece.
Tries to eat the given number of pieces from the front of the pack, however,
You can't eat pieces that aren't there - the actual number of pieces eaten is limited to the number of pieces
currently in the pack
Pieces that are eaten are removed from (the front) of the pack
returns a list of the pieces actually eaten. If none are eaten, an empty list is returned.
image text in transcribed

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

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

Students also viewed these Databases questions

Question

Understand the post-crisis debate on HRM and pedagogy

Answered: 1 week ago