[PDF] [PDF] Page 1 of 7 Practical Sheet: OOP Programming This sheet is a set of

18 fév 2018 · This sheet is a set of exercises for introducing OOP in Python using the turtle The notes assume knowledge of basic Python programming



Previous PDF Next PDF





[PDF] Download Object Oriented Python Tutorial - Tutorialspoint

Python, an Object Oriented programming (OOP), is a way of programming that focuses on using objects and classes to design and build applications Major pillars 



[PDF] Object oriented programming with Python - CSC

9 00-9 45 Object oriented programming with Python 9 45-10 30 Exercises 10 30-10 45 Coffee break 10:45-11:15 NumPy – fast array interface to Python



[PDF] Python School OOP and Design patterns Exercises

Python School OOP and Design patterns Exercises Authors: Bartosz Telenczuk, Niko Wilbert 1 (20 min) The graph module (provided in the repository) 



[PDF] Object-Oriented Programming in Python - Read the Docs

15 nov 2017 · Object-Oriented Programming in Python Documentation, Release 1 Contents the exercises in this module, you should use the official Python 



[PDF] Object Oriented Programming in Python (New Sheet) - Pattern

Exercise 26 Programming Task: This exercise introduces Object Oriented Programming with Python The goal is to write classes to apply a filter kernel to an 



[PDF] Object-Oriented Programming in Python – The Best - Dan Bader

In this Real Python tutorial you'll learn the fundamentals of object-oriented programming (OOP) in Python and how to work with classes, objects, and con- structors



[PDF] Object Oriented Programing in Python

Always define your data attributes in __init__ • Class attributes are shared across all instances •Object Oriented Programming in Python Python Classes in Detail 



[PDF] Page 1 of 7 Practical Sheet: OOP Programming This sheet is a set of

18 fév 2018 · This sheet is a set of exercises for introducing OOP in Python using the turtle The notes assume knowledge of basic Python programming



[PDF] Exercise 5 – OOP with Inheritance in Python - Interactive Zoo

This assignment will focus on the student becoming familiar with python and object oriented programming using inheritance The emphasis will be on design and 

[PDF] object oriented programming python projects

[PDF] object oriented programming short notes pdf

[PDF] object oriented analysis and design advantages and disadvantages

[PDF] object oriented analysis and design example

[PDF] object oriented analysis and design python

[PDF] object oriented analysis and design with applications 4th edition pdf

[PDF] object oriented approach

[PDF] object oriented design patterns

[PDF] object oriented javascript pdf

[PDF] object oriented javascript tutorial point

[PDF] object oriented php junade ali pdf

[PDF] object oriented php peter lavin

[PDF] object oriented programming in javascript with examples pdf

[PDF] object oriented programming paradigm

[PDF] object oriented programming with abap objects

CASLondonCPDDayFebruary18

Page 1 of 7

PracticalSheet:OOPProgramming

• Anoverviewpresentation • Additionalpresentations(notused)onOOPfeaturesofPython • Ashortsummaryof

Contents

TurtleGraphics

CASLondonCPDDayFebruary18

Page 2 of 7

1 Exercise 1: Using Objects

codeprovidedhastwofiles:

1. Thefileface.pycontainsaFaceclass,whichdrawsaface.

2. Thedrawing.pyfileusestheFaceclasstodrawseveralfaces.

Exercise1.1:RuntheProgram

from turtle import * from Face import Face # start of drawing code f1 = Face(0, 0) f1.draw() f2 = Face(-200, 0) f2.setSize(80) f2.draw()

Exercise1.2:Listtheattributesandmethods

AttributeParameterof

constructor?

Functiontoset?

posYesNo sizeYes

Exercise1.3:MakeaMoreComplexDrawing

object(orinstanceofaclass).

CASLondonCPDDayFebruary18

Page 3 of 7

2 Exercise 2: Adding Attributes

• WeaddamethodtobeabletosetthenoseSizeattribute. • Weaddmoreattributes.Foreachattributeweshould o Initialisetheattributeintheconstructor,decidingwhethertousea o Decidewhethertoprovideamethodtoset(orget)theattributevalue

Exercise2.1:VarytheSizeoftheNose

1 .We

Exercise2.2:VarytheHairColour

1. Addanattributeintheconstructor-giveitadefaultvalue

2. Createamethodtosettheconstructorandupdatethevalue

3. Modifythefunctiondrawingthehair

4. Enhancethedrawingtodrawfaceswithdifferenthair

Drawfaceswithdiffercolourhair.

Exercise2.3:VarytheLengthoftheHair

normal,....

Hereisapossiblesolution:

Exercise2.4:OtherDifferences

exerciseforschoolpupilsconsider: • Howeasywoulditbetocreatethisdifference? • Whatprogrammingprinciplewouldbeillustrated? 1

CASLondonCPDDayFebruary18

Page 4 of 7

• Wouldthepupilsfinditmotivating? values

3 Exercise 3: Multiple Classes

Exercise3.1:TheHairClass

1. Ratherthanhavingattributes'hairLength'and'hairColour',afacenowhasa'hair'

attribute.

2. Intheconstructorforthehairobject,weshowwhichFacethehairisin.Lookat

howthisisdone.

3. Itisstillpossibletochangethehaircolouretc.butnowthisisdonebyaskingthe

4. Whendrawingtheface,weaskthehairtodrawitself.

IntheHairclass,lookforthefollowing:

1. Thehairknowswhichfaceitispartof.Whatdoesitusethisfor?

2. Twofunctionsareusedtodrawthehair:whatarethey?

Exercise3.2:TheEyeClass

Makethefollowingchanges:

1. Createthenewclass,rememberingtoimporttheTurtlelibrary

2. Createaconstructor.Theeyeneedstoknow:

a. Whichfaceitispartof(liketheHair) b. Whichsideofthefaceitisone(leftorright)

3. Createadrawfunction,basedonthedrawEyefunctionfromtheFaceclassbut

adaptedtousetheattributes.

4. ModifytheFaceclasstousetheEyeclass

a. Remembertoimportit b. IntheFaceconstructor,createtwonew'Eye'instance(aleftoneanda rightone)

CASLondonCPDDayFebruary18

Page 5 of 7

c. RemovethedrawEyefunction:adapttheFace'sdrawfunctiontoaskthe twoeyestodrawthemselves.

Exercise3.3:MakingEyeMoreElaborate

youcouldhaveacolourattribute.

4 Exercise 4: Inheritance

faces: • Agirl'sface • Aboy'sface • Aman'sface • Awoman'sface

Exercise4.1:TheGirlsFaceClass

• AGirlsFaceisakindofFace • GirslsFaceinheritsFace • FaceissuperclassofGirlsFace • GirlsFaceisaspecialisationofFace • Ithasit'sownconstructor,butitmustalsocalltheconstructorofitssuperclass. • Itcancallthemethodofitssuperclass-lookathowthisisdone.

Exercise4.2:AddingEyebrows

haseyebrows.

Exercise4.3:CreateOtherSpecialisedFaces

5 Exercise 5: A Family Class

• Keepthepeopleinalist. • Haveamethodtoaddpeopletothefamily • Haveamethodtodrawthefamilyportrait. someofitrandomly.

CASLondonCPDDayFebruary18

Page 6 of 7

6 Appendix: Turtle Graphics Function Reference

ThePythonturtlegraphicspackagehasboth

• Afunctionalinterface • Anobject-orientedinterface

FunctionDescriptionandExample

MoveandDraw

forward(), backward()

Movetheturtleadistance:forward(10)

right(),left()Turnbyanangle:right(90) goto()Movetoan(x,y)position:goto(10, 50) home()Movetothehomeposition:home() circle()Drawacircleorarc.Examples: • circle(100)-drawacircleofradius100 • circle(50, 90)-drawanarcofradius50,angle90 dot()Drawadotwithdiameter&colour:dot(20, 'blue')

TurtlePosition

heading()Gettheheading:angle = heading() xcor(),ycor()Getthexorycoordinates:currentX = xcor() dist = distance(50, 75) ordinates:towards(100, 100)

PenandTurtle

pendown(), penup() drawsaline. isdown()Returnstrueifthepenisup. showturtle(), hideturtle()

CASLondonCPDDayFebruary18

Page 7 of 7

FunctionDescriptionandExample

FillingandClearing

otherformatssupported:fillcolor('blue'). begin_fill(), end_fill() shouldbefilled. reset()Reseteverything. turtleisatthelefthandofthestring.

Screen

screensize(500, 300) textinputInputtextusingadialog:textinput("Title", "Prompt") numinputInputanumber window_height, window_width

Getthewindowheightorwidth

quotesdbs_dbs20.pdfusesText_26