Computer Science, asked by dorcaskimani282, 28 days ago

print the average of 3 numbers entered by the user creating a class named average, having a function to calculate and print the average without creating any object of the average class

Answers

Answered by Anonymous
2

Required program is in attachment

This question is about creating a class named average having a function to calculate the average of 3 numbers which are entered by the user.

In order to solve this question, we should have a basic knowledge about object and classes. To create a class, we use 'class' keyword and inside this class, we have created a function by using 'def' keyword. Remember not to add 'self' parameter inside the function.

Now the question arises why we don't have to add self parameter. Answer is simple, self represents the ìnstance of the class (i.e. object). In this question we are not allowed to create any object or ìnstàntiation.

Now pàss data to our function, create three variables and take inputs of three numbers from the user and then print the average of those input values by using print() function.

Now càll the function of the class by using following syntax:-

  • className.functionName()

Output attached . . . ✦

Attachments:
Similar questions