Skip to main content
elearn.ellak.gr
  • Home
  • More
You are currently using guest access
Log in
Home
  1. Open Courses in English
  2. python_lab_ellak
  3. Module 7
  4. Assignment 7.1
Assignment

Assignment 7.1

Assignment 7.1

Completion requirements
View

We have learned how to create classes and objects.

Create a new program, test it and upload it using your name and followed by AS7.1 in the programs file name. As an example a programs filename could be Name_Surname_AS7.1.py

For your effort you will be graded and you will have another try if you want to get a better grade. Passing grade is 60%

The program should start with three class definitions, then code that will create instances of each class.

Write code that defines a class named Animal:

  •         Add an attribute for the animal name.
  •         Add an eat() method for Animal that prints ``Munch munch.''
  •         A make_noise() method for Animal that prints ``Grrr says [animal name].''
  •         Add a constructor for the Animal class that prints ``An animal has been born.''

A class named Cat:    

  •         A make_noise() method for Cat that prints ``Meow says [animal name].''
  •         A constructor for Cat that prints ``A cat has been born.''

A class named Dog:

  •         A make_noise() method for Dog that prints ``Bark says [animal name].''
  •         A constructor for Dog that prints ``A dog has been born.''
  •         Modify the constructor so it calls the parent constructor as well.

A main program with:

  •         Code that creates a cat, two dogs, and an animal.
  •         Sets the name for each animal.
  •         Code that calls eat() and make_noise() for each animal. 

python classes video

◄ Check List of Module 7
Worksheet 07 ►
Contact site support
You are currently using guest access (Log in)
Data retention summary
Get the mobile app
Powered by Moodle