Free online Python course for kids - Programming for Beginners

Which Dog?

Session 7: Creating a Dog Adoption Recommendation Program

Course Overview | Previous Session | Next Session

Introduction

The local animal shelter is busier than ever, and they need a special software tool to help people choose the perfect dog breed for their home. We’re going to help by creating a program that asks potential adopters for their name and age and then recommends a dog breed that fits them best.

Imagine you’re at the shelter, and it’s your first day on the job as a junior programmer. The shelter manager, Mrs. Thompson, comes up to you with a big smile. She says, “We’re getting so many visitors interested in adopting dogs, but they’re unsure which breed suits them best. Can you create a program that helps us recommend the perfect dog for each person based on their age?”

You’re excited about the challenge and ready to create a program that will make the adoption process easier and more enjoyable for everyone.

Requirements

  1. Input: The program should ask for the user’s name and age.
  2. Decision Making: Use if, elif, and else statements to recommend a dog breed based on the user’s age.
  3. Output: Print a personalized message with the recommended dog breed.

In this session, we’ll use comparison operators to make decisions based on the user’s age. These operators are crucial for creating conditions in our program:

  • < (Less Than): Checks if one value is smaller than another. For example, age < 18 checks if the user is younger than 18.
  • <= (Less Than or Equal To): Checks if one value is smaller than or equal to another. For example, age <= 40 checks if the user is 40 or younger.

Open your text editor, create a new file, and save it as adoption_age.py inside the code directory. Copy and paste the following code:

name = input("What is your name? ")
age = int(input("How old are you? "))

if age < 18:
  print(f"Hello {name}, we recommend a Golden Retriever puppy for you!")
elif age >= 19 and age <= 40:
  print(f"Hello {name}, we recommend a German Shepherd for you!")
elif age >= 41 and age <= 60:
  print(f"Hello {name}, we recommend a Labrador Retriever for you!")
else:
  print(f"Hello {name}, we recommend a small dog breed, such as a Poodle or a Chihuahua, for you!")
  1. Inputs: The program starts by asking for the user’s name and age using the input() function.
  2. Decision Making: We use if, elif, and else statements to decide which dog breed to recommend based on the user’s age:
    • If the user is under 18, they get a recommendation for a Golden Retriever puppy.
    • Elif the user is between 19 and 40, they get a recommendation for a German Shepherd.
    • Elif the user is between 41 and 60, they get a recommendation for a Labrador Retriever.
    • Else if the user is over 60, they get a recommendation for a small dog breed.
  • Open the terminal inside the code folder.
  • Run the program by typing:
  • Follow the on-screen instructions to see your personalized dog breed recommendation.

To further practice, try making changes to the program:

  • Change Breeds: Replace the recommended dog breeds with your favorites.
  • Add New Breeds: Add a new breed to the else statement, such as a Boxer.

For example:

  • Change Golden Retriever to Beagle.
  • Change German Shepherd to Rottweiler.
  • Swap Labrador Retriever with Pug.

Feel free to get creative and see how your changes affect the program!

Study Tip

As you modify the code, pay close attention to how the if, elif, and else statements work together to make decisions. This will help you understand how to create more complex programs in the future.


Course Overview | Previous Session | Next Session