Question
PYTHON 3 First one: A GirlScout constructor takes two arguments, name and num_cookies_sold. The default value of num_cookies_sold is 0. It has two additional methods.
PYTHON 3
First one:
A GirlScout constructor takes two arguments, name and num_cookies_sold. The default value of num_cookies_sold is 0. It has two additional methods.
1. badge_earned() that returns True if the Girl Scout has sold 100 or more cookies and False otherwise.
2. cookies_sold() returns a string of the form "{Scout's name} has sold {number} cookies"
Sample usage:
scout = GirlScout('Jane Doe') print(scout.badge_earned()) # prints False scout.cookies_sold() # returns "Jane Doe has sold 0 cookies" scout = GirlScout('Jane Doe', 150) print(scout.badge_earned()) # prints True scout.cookies_sold() # returns "Jane Doe has sold 150 cookies"
Second one:
Cookies is a class that keeps track of how many of each kind of cookie has been sold. Its constructor takes no arguments.
1. add_type(cookie_name) instructs the object to begin tracking sales of cookie_name cookies. When a new cookie is tracked, its sales are initialized to 0
2. update_sales(cookie_name, num_sold) adds num_sold to cookie_name's sales
3. print_sales() prints a report of sales for each cookie, one cookie per line. Each cookie's report is of the form "{cookie's name}: {number sold}"
Sample usage:
cookies = Cookies() cookies.add_type('Thin Mints') cookies.add_type('Tagalongs') cookies.add_type('Smores') cookies.update_sales('Tagalongs',50) cookies.update_sales('Smores',6) cookies.print_sales() # output follows Thin Mints: 0 Tagalongs: 50 Smores: 60
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started