2 Replies - 163 Views - Last Post: 02 December 2019 - 09:15 AM Rate Topic: -----

#1 saar ah   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 20-October 19

ZOO CLASS

Posted 01 December 2019 - 08:48 PM

hi'
i need to built a class for zoo
and i need some help

that is the code so far
==================
class Animal:
    def __init__(self,_name,_hunger ):
        self._name =_name
        self._hunger= 0

    class Dog():
        def __init__(self,_name,_hunger ):
            pass
        
    class cat():
        def __init__(self,_name,_hunger ):
            pass
        
    class Skunk():
        def __init__(self,_name,_hunger ):
            pass
        
    class Unicorn():
        def __init__(self,_name,_hunger ):
            pass
        
    class Dragon():
        def __init__(self,_name,_hunger ):
            pass

def main():
  
    for animal in zoo_lst:
        while animal.is_hungry():
             animal.feed()
:code:
======================

id have to Write a main function called main that performs the following tasks:

Creates one animal of each type (Unicorn, Skunk, Cat, Dog, and Dragon) and initializes it with the values listed in the table. She keeps the shows of the animals in the list called zoo_lst.
Goes through the animals in the zoo_lst list using the for loop. For each hungry animal, prints its type (type, subdivision name) and its name (name_) and then feeds it until it is no longer hungry (that is, until its degree of hunger is 0).
Instructions: You can use the following code skeleton.

any help how to start ?
and where to put the main def ?

This post has been edited by modi123_1: 01 December 2019 - 11:30 PM
Reason for edit:: In the future please use the [code] tag button in the editor


Is This A Good Question/Topic? 0
  • +

Replies To: ZOO CLASS

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15434
  • View blog
  • Posts: 61,848
  • Joined: 12-June 08

Re: ZOO CLASS

Posted 01 December 2019 - 11:32 PM

Moving to the python area, and adding the code tags.

What have you thought about, tried, or considered?
Was This Post Helpful? 0
  • +
  • -

#3 DK3250   User is offline

  • Pythonian
  • member icon

Reputation: 562
  • View blog
  • Posts: 1,798
  • Joined: 27-December 13

Re: ZOO CLASS

Posted 02 December 2019 - 09:15 AM

The code skeleton is peculiar. It uses nested classes - this is a legal construct in python, but here I find it inappropriate.
I suggest the class Animal() as a parent class; all the individual animal classes then inheritances from Animal.

I'd like to help but you need to show a decent attempt - the code skeleton doesn't reveal how you plan to solve this taks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1