← Back to challenges

Classes For Fetching Information on a Sports Player

PythonHardclassesobjectsstrings

Instructions

Create a class that takes the following four arguments for a particular football player:

  • name
  • age
  • height
  • weight

Also, create three functions for the class that returns the following strings:

  • get_age() returns "name is age age"
  • get_height() returns "name is heightcm"
  • get_weight() returns "name weighs weightkg"

Examples

 p1 = player("David Jones", 25, 175, 75)

 p1.get_age() ➞ "David Jones is age 25"
 p1.get_height() ➞ "David Jones is 175cm"
 p1.get_weight() ➞ "David Jones weighs 75kg"

Notes

name will be passed in as a string and age, height, weight will be integers.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Fullname and Email