Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Homework help
#12
So I created a python file called useful_turtle_functions and saved it to the same folder as the file I would like to import this into.
def drawLine(x1, y1, x2, y2):
    print('drawLine called {}, {}, {}, {}'.format(x1, y1, x2, y2))

def writeText(s, x, y):
    print('writeText called {}, {}, {}'.format(s, x, y))

def drawPoint(x, y):
    print('drawPoint called {}, {}'.format(x, y))

def drawCircle(x, y, radius):
    print('drawCircle called {}, {}, {}'.format(x, y, radius))

def drawRectangle(x, y, width, height):
    print('drawRectangle called {}, {}, {}, {}'.format(x, y, width, height))
then I can do
import useful_turtle_functions

useful_turtle_functions.drawLine('x1', 'y1', 'x2', 'y2')
useful_turtle_functions.writeText('s', 'x', 'y')
useful_turtle_functions.drawPoint('x', 'y')
useful_turtle_functions.drawCircle('x', 'y', 'radius')
useful_turtle_functions.drawRectangle('x', 'y', 'width', 'height')
which gave
Output:
drawLine called x1, y1, x2, y2 writeText called s, x, y drawPoint called x, y drawCircle called x, y, radius drawRectangle called x, y, width, height
Reply


Messages In This Thread
Homework help - by nzieno - Oct-07-2016, 04:00 PM
RE: Homework help - by Ofnuts - Oct-07-2016, 05:15 PM
RE: Homework help - by Yoriz - Oct-07-2016, 05:19 PM
RE: Homework help - by nzieno - Oct-07-2016, 05:53 PM
RE: Homework help - by metulburr - Oct-07-2016, 05:57 PM
RE: Homework help - by nzieno - Oct-07-2016, 06:14 PM
RE: Homework help - by nilamo - Oct-07-2016, 06:39 PM
RE: Homework help - by nzieno - Oct-07-2016, 08:26 PM
RE: Homework help - by nilamo - Oct-07-2016, 08:42 PM
RE: Homework help - by wavic - Oct-07-2016, 09:49 PM
RE: Homework help - by nzieno - Oct-07-2016, 11:44 PM
RE: Homework help - by Yoriz - Oct-08-2016, 08:12 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020