Width = int(t.numinput("Cartesain Coordinates", "Enter Width",200, minval = 200, maxval = 400))
Height = int(t.numinput("Cartesain Coordinates", "Enter Height", 200, minval = 200, maxval = 400))
Grid = t.textinput("Cartesian Coordinates", "Would you like a grid?")
# Pen size, pen speed, and pen color
t.pensize(5)
t.speed(10)
t.pencolor("black")
# User width (x)
if Width == +Width:
t.goto(+Width, 0)
t.goto(-Width, 0)
elif Width == -Width:
t.goto(-Width, 0)
t.goto(+Width, 0)
t.goto(0, 0)
# User Height (y)
if Height == +Height:
t.goto(0, +Height)
t.goto(0, -Height)
elif Width == -Height:
t.goto(0, -Height)
t.goto(0, +Height)
t.goto(0, 0)
t.penup()
# Setting grid pen size, color and speed
t.pensize(1)
t.pencolor('Gray')
t.speed(4)
# Defualt value for numinputs (x)
Default_width_value = 200
# List of possible (x) values
Possible_width_value1 = 250
Possible_width_value2 = 300
Possible_width_value3 = 350
Max_width_value = 400
# Starting the grid
if Grid == 'No':
t.goto(0, 0)
if Grid == 'Yes':
Grid = True
while True:
# The Outter Square
t.goto(-Width, +Height)
t.pendown()
t.goto(-Width, -Height)
t.goto(+Width, -Height)
t.goto(+Width, +Height)
t.goto(-Width, +Height)
# The Inner Lines For Width (x) portion of Grid
# First Line
t.goto(-Width, -Height)
t.forward(50)
t.pendown()
t.left(90)
t.forward(+Height)
t.forward(+Height)
# Second Line
t.right(90)
t.forward(50)
t.right(90)
t.backward(-Height)
t.backward(-Height)
# Third Line
t.left(90)
t.forward(50)
t.left(90)
t.forward(+Height)
t.forward(+Height)
# Fourth Line
t.right(90)
t.forward(50)
t.right(90)
t.backward(-Height)
t.backward(-Height)
# Fifth Line
t.left(90)
t.forward(50)
t.left(90)
t.forward(+Height)
t.forward(+Height)
# Sixth Line
t.right(90)
t.forward(50)
t.right(90)
t.backward(-Height)
t.backward(-Height)
# Seventh Line
t.left(90)
t.forward(50)
t.left(90)
t.forward(+Height)
t.forward(+Height)
if Width > Default_width_value < Possible_width_value1:
# First Line
t.right(90)
t.forward(50)
t.right(90)
t.backward(-Height)
t.backward(-Height)
# Second Line
t.left(90)
t.forward(50)
t.left(90)
t.forward(+Height)
t.forward(+Height)
elif Width > Possible_width_value1 < Possible_width_value2:
# Third Line
t.right(90)
t.forward(50)
t.right(90)
t.backward(-Height)
t.backward(-Height)
# Fourth Line
t.left(90)
t.forward(50)
t.left(90)
t.forward(+Height)
t.forward(+Height)
elif Width > Possible_width_value2 < Possible_width_value3:
# Fifth Line
t.right(90)
t.forward(50)
t.right(90)
t.backward(-Height)
t.backward(-Height)
# Sixth Line
t.left(90)
t.forward(50)
t.left(90)
t.forward(+Height)
t.forward(+Height)
elif Width > Possible_width_value3 < Max_width_value:
# Seventh Line
t.right(90)
t.forward(50)
t.right(90)
t.backward(-Height)
t.backward(-Height)
# Eighth Line
t.left(90)
t.forward(50)
t.left(90)
t.forward(+Height)
t.forward(+Height)
else:
t.penup()
t.goto(0, 0)
First id like to say that im very new to python
The issue is when creating a grid for a cartesian coordinate, i can get it to create the grid at the minval() but once i start increasing in increments of 50 till maxval() is where i have trouble. ive tried to put the if() in the while loop, which is where i found the problem, ive also tried it out side which is where it worked fine whilest increasing in incraments of 50 but the issue i had there was it would still try and draw part of the grid even if the user said no to the grid. Its for an assinment and i can only use whats in the turtle module. Any help is very much appreciated.
Dylan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.