Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 11.2, Problem 5CP

Look at the following class definitions:

  class Vegetable:

  def _ _init_ _(self, vegtype):

  self._ _vegtype = vegtype

  def message(self):

  print("I'm a vegetable.")

  class Potato(Vegetable):

def_ _init_ _(self):

  Vegetable._ _init_ _(self, 'potato')

  def message(self):

  print("I'm a potato.")

Given these class definitions, what will the following statements display?

  v = Vegetable('veggie')

  p = Potato()

  v.message()

  p.message ()

Blurred answer
Students have asked these similar questions
Create a class called ship that incorporates a ship’s serial number and location. Create another class angle which has two variables latitude and longitude. A member function of the ship class should get a position from the user and store it. Create object that should report the serial number and position. Write a main () program that creates three ships, asks the user to input the position of each, and then displays each ship’s serial number and position.Identify all the classes implement inheritance between them.   (language cpp)
Q2. Write a class Bank that has the following data members –Account Holder name (ah_name[]) –Account number (ac_number) •Must unique, system generates automatically, and must starting from 100 (Hints: Use another static variable and assign that variable to ac_number) –Balance in the account (ac_balance) •The class has the following member functions –A constructor to initialize the data members –Input() to takes name from the user –Deposit(parameter) to deposits balance in the account •Must accept parameter (The amount to deposit) –Withdraw(parameter) to withdraws balance after checking •Must accept parameter (The amount to withdraw) –Display() to show the name, account number, and balance
Parent Class: Food Write a parent class called Food. A food is described by a name, the number of grams of sugar (as a whole number), and the number of grams of sodium (as a whole number).  Core Class Components For the Food class, write: the complete class header the instance data variables a constructor that sets the instance data variables based on parameters getters and setters; use validity checking on the parameters where appropriate a toString method that returns a text representation of a Food object that includes all three characteristics of the food Class-Specific Method  Write a method that calculates what percent of the daily recommended amount of sugar is contained in a food. The daily recommended amount might change, so the method takes in the daily allowance and then calculates the percentage. For example, let's say a food had 6 grams of sugar. If the daily allowance was 24 grams, the percent would be 0.25. For that same food, if the daily allowance was 36 grams, the…
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
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY