livepython.net

181. Python Program to Find the Older Pet Using Objects

MediumClasses

Overview

Two objects from one class, each with its own attributes, compared with if.

Problem Statement

Define a class called Pet. Read the name and age of a first pet, then the name and age of a second pet. Make one Pet object for each, with the attributes name and age (a whole number). Then compare the two ages and print one line:

  • Rocky is older, with the name of the older pet, or
  • Rocky and Lucky are the same age, with the first pet's name first, if the ages are equal.

Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Input

Four lines: first name, first age, second name, second age. Example:

Rocky
5
Lucky
3

Output

The output for that example:

Rocky is older

The tests try 4 different inputs.

Learn this firstChapter 20 · Python Classes and Objects for Beginners
solution.py
# write your code here

EXPECTED OUTPUT

1Rocky is older

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.