Friday, November 21, 2025

Week 6 Assignments

1. Mind reader:

Your computer tells you it has mind reading capabilities.  You certainly don't buy that because you go to the Opportunity Class.  Your computer suggests a game with which it will show you that it reads your mind.

You give it a range, like 1..100, and the computer guesses an integer within that range.  All you need to do is tell it 'too large' or 'too small'.  You two repeat this Q&A until the computer guesses the correct number you have in mind.  By doing so you are able to tell if the computer can really read your mind, or it's simply doing maths.

Input 2 integers that indicate the range.  For each integer the computer guesses, input 'too large''too small''correct', or 'quit'.  The game ends when the input is 'correct' or 'quit'.  The computer outputs the integer you have in mind, and the number of guesses taken.  If the computer finds out you are trying to cheat, it also ends guessing and outputs 'you can't fool me!'.

2. Kitty:

Follow the definition of the Dog class, create a Cat class which describe this adorable animal which:

  • has a name
  • an age
  • a breed
  • a colour
  • once first adopted (instantiated), can populate its properties based on input
  • can output it's own properties, by saying like 'my name is Kitty'
  • can purr, and say 'I'm happy that's why I'm purring'
  • can curl, and say 'zzz...'

3. Cat breeder:

You started a cat breeder business.  You want to keep track of all your cats by using Classes in Python.  Yesterday a batch of new kitties arrived, together with a file describing them.  File name is kitties.txt, format is

            name     age    breed    colour
            name     age    breed    colour
            name     age    breed    colour
            name     age    breed    colour
            ...

Please read from the text file, use the Cat class created in the previous problem to capture all the information.  (*think: now you have more than one cat, you'll have more than one Cat class variables.  Where should you put all these variable?)  

Note that your kitties, i.e., variables of this Cat class, in addition to what they can already do in the previous problem, can also to the following:

  • Get into the front of a line
  • Get into the end of a line
Once you get them all in a line, please print their names in their current order.

No comments:

Post a Comment