11/01/2020

Python Explanation(Edabit //Classes For Fetching Information on a Sports Player)

 Hello!

Today it is going to be an python explatnation!

Today's question:

Create a class that takes the following four arguements 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


My code!

class player():

def __init__(self, name, age, height, weight):
self.name = name
self.age = age
self.height = height
self.weight = weight

def get_age(self):
return '{} is age {}'.format(self.name, self.age)

def get_height(self):
return '{} is {}cm'.format(self.name, self.height)

def get_weight(self):
return '{} weighs {}kg'.format(self.name, self.weight)

Let's see.

There is four instances : Name, Age, height, weight in a class called player.

Next, we have 3 functions,

The first function is about the age off the foot ball player.

You can return the name and the age.

So, you can use format to put the name, and the age.

The second function is similar, return the name and the height.

You can use format to take the name and the height.

It's the same pattern, the third function is to return the name and the weight.

Use the format to take the name and the weight.

It was easy!!!!!


Bye!!!!!


 

0 件のコメント:

Super Leo 4!

  Leo : Let's do this! Reimu : I'll kill those monsters, so you go! Leo : Yeah! I'll go to the goal!  Leo : Let's go〜! ? Wai...