CSC148H1 Study Guide - Final Guide: Init

65 views1 pages
16 Oct 2011
School
Course
Professor
katrinasavvy and 38715 others unlocked
CSC148H1 Full Course Notes
1
CSC148H1 Full Course Notes
Verified Note
1 document

Document Summary

""" the duck allows users to play with it in duck-like ways. """ def __init__(self, name = "sir quacks-a-lot", position = 0): """ create a duck with a name, a given position, and an empty stomach self. name = name self. position = position self. stomach = [] def swim(self, distance = 1): """ move the duck forward the given distance. """ self. position += distance def eat(self, fish = none): """ ingests the fish provided. """ self. stomach. append(fish) def quack(self): """ make a quacking sound. """ print "quack" class rubberduck(duck): """ a duck-like toy for playing in the bathtub. """ def __init__(self, name, position, colour): """ create a rubberduck with a name, a given position, an empty stomach, and a given colour. """ super(rubberduck, self). __init__(name, position) self. colour = colour def get_colour(self): return self. colour def quack(self):

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents

Related Questions