Read first
Task 55
Model a student with a class
A class keeps data and behaviour together. `__init__` runs when the object is built, and a method is just a function that can see `self`.
Task
Task: Model a student with a class. What does this program print?
The editor already contains a starting point. Change it until every check passes — the Next task button unlocks when it does.
What you start with
class Student:
def __init__(self, name, course, fee):
self.name = name
self.course = course
self.fee = fee
def yearly(self):
return self.fee * 12
s = Student("Ayesha", "Python", 10000)
print(s.name, "-", s.course)
print("Yearly:", s.yearly())
Python
1 automatic check Capstone: five small programs
Code editor
Ctrl + Enter runs
Run your code to see the output and the checks.
Your result
Submit your code to see results
Write your code in the middle column and press Run code.
Next task (pass every check first)
Hint
Ask yourself: Task: Model a student with a class. What does this program print?