Fruit¶
Some fruits
This file is an example of Sage conventions for syntax and documentation. It also serves as an example to explain class inheritance: methods defined for fruits are automatically defined for bananas and strawberries.
AUTHORS:
Sébastien Labbé, 2010-2013
EXAMPLES:
sage: from slabbe import Fruit
sage: f = Fruit(5)
sage: f
A fruit of 5 kilos.
sage: f.weight()
5
sage: f.is_a_fruit()
True
Because of class inheritance which says that a banana is a fruit and a strawberry is a fruit, the methods written for fruits are defined for bananas and strawberries automatically:
sage: from slabbe import Strawberry
sage: s = Strawberry(32)
sage: s
A strawberry of 32 kilos.
sage: s.weight()
32
sage: s.is_a_fruit()
True
sage: from slabbe import Banana
sage: b = Banana(13)
sage: b
A banana of 13 kilos.
sage: b.weight()
13
sage: b.is_a_fruit()
True
sage: s = Strawberry(32)
sage: t = Strawberry(7)
sage: s
A strawberry of 32 kilos.
sage: t
A strawberry of 7 kilos.
sage: s + t
A strawberry of 1073 kilos.
- class slabbe.fruit.Banana(weight=1)¶
Bases:
slabbe.fruit.Fruit
Creates a banana.
INPUT:
weight
- number, in kilos
OUTPUT:
Banana
EXAMPLES:
sage: from slabbe import Banana sage: b = Banana(9) sage: b A banana of 9 kilos.
TESTS:
Testing that pickle works:
sage: loads(dumps(b)) A banana of 9 kilos. sage: b == loads(dumps(b)) True
Running the test suite:
sage: TestSuite(b).run()
- class slabbe.fruit.Fruit(weight=1)¶
Bases:
sage.structure.sage_object.SageObject
Creates a fruit.
INPUT:
weight
- number, in kilos
OUTPUT:
Fruit
EXAMPLES:
sage: from slabbe import Fruit sage: f = Fruit(5) sage: f A fruit of 5 kilos.
- is_a_fruit()¶
Returns True if it is a fruit.
OUTPUT:
Boolean
EXAMPLES:
sage: from slabbe import Fruit sage: f = Fruit(3) sage: f.is_a_fruit() True
- weight()¶
Return the weight.
OUTPUT:
Number
EXAMPLES:
sage: from slabbe import Fruit sage: f = Fruit(3) sage: f.weight() 3
- class slabbe.fruit.Strawberry(weight=1)¶
Bases:
slabbe.fruit.Fruit
Creates a strawberry.
INPUT:
weight
- number, in kilos
OUTPUT:
Strawberry
EXAMPLES:
sage: from slabbe import Strawberry sage: s = Strawberry(34) sage: s A strawberry of 34 kilos.
TESTS:
Testing that pickle works:
sage: loads(dumps(s)) A strawberry of 34 kilos. sage: s == loads(dumps(s)) True
Running the test suite:
sage: TestSuite(s).run()