Mar-21-2020, 01:23 PM
Hello everyone,
I want to draw a simple house with several windows and a door by using the python turtle inferface.
The window(s) and door(s) have to be implemented by modular programming. In principle I am successful in it (see program code below).
So something like this:
So in the end I do want to create modularity by using seperate programs (*py) rather than using seperate def-commands within the mnain program.
I hope somebody can help me out
Waiting for your response
I want to draw a simple house with several windows and a door by using the python turtle inferface.
The window(s) and door(s) have to be implemented by modular programming. In principle I am successful in it (see program code below).
import turtle def contour(): turtle.left(90) turtle.forward(200) turtle.right(45) turtle.forward(142) turtle.right(90) turtle.forward(142) turtle.right(45) turtle.forward(200) turtle.right(90) turtle.forward(200) def window(): turtle.seth(90) for a in range (4): turtle.forward(30) turtle.right(90) def door(): turtle.seth(90) turtle.forward(60) turtle.right(90) turtle.forward(30) turtle.right(90) turtle.forward(60) turtle.right(90) turtle.forward(30) contour() turtle.pu() turtle.goto(25,150) turtle.pd() window() turtle.pu() turtle.goto(85,150) turtle.pd() window() turtle.pu() turtle.goto(85,0) turtle.pd() door() turtle.done()But instead of defining CONTOUR, WINDOW and DOOR at the beginning of the main program HOUSE.py, I would like to have the contour, windows and doors as seperate independent programs CONTOUR.py, DOOR.py and WINDOW.py and then "import" them in the main program HOUSE.py.
So something like this:
import turtle contour.py #Which command is needed to execute the program "contour.py" turtle.pu() turtle.goto(25,150) turtle.pd() window.py turtle.pu() turtle.goto(85,150) turtle.pd() window.py turtle.pu() turtle.goto(85,0) turtle.pd() door.py turtle.done()I have tried to solve the problem with the command import [NAME OF THE PROGRAM] but then I have to create a new turtle in each program. This then results in several turtles with its own different positions, which is not wanted, since modularity is not given than any more.
So in the end I do want to create modularity by using seperate programs (*py) rather than using seperate def-commands within the mnain program.
I hope somebody can help me out
Waiting for your response