class Student: def __init__(self, Name, wasPicked=False): """ Creates a student named 'Name' <str> and sets a boolean for if they have been selected before or not 'wasPicked' <bool> """ self._name = Name self._picked = wasPicked def pick(self): """ sets the _picked field to True """ self._picked = False def deselect(self): """ sets the _picked firle to False """ self._picked = False def whoIs(self): """ Gets the name of the student """ return self._name def wasPicked(self): """ Gets the picked data of a student """ return self._picked ## By using the str() command it guarentees that they are strings ## NOTE: in the print statement functions I concatinate 'Student(' so that during debugging I know what class it's from. def __str__(self): return "Student("+str(self._name)+")" ## Allows the class to be printed with the 'print' command def __repr__(self): return "Student("+str(self._name)+")" ## Allows the class to be printed with the 'print' command
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question