Hello! I am using python as my first programming language, with this being my third week of class. I have the following code, however, there is no output. The turtle program should be giving me squares as the output.
I have figured out that if _ name _ == ‘_ main ': is invalid, and modified the code to
if name == ’ main _’:
The code will run without errors, however, there is no output. Can someone tell me what I am missing?
# START OF CODE
#(draw_squares.py)
import turtle
def main():
square(100, 0, 50, 'red')
square(-150, -100, 200, 'blue')
square(-200, 150, 75, 'green')
# The square function draws a square. The x and y parameters
# are the coordinates of the lower-left corner. The width
# parameter is the width of each side. The color parameter
# is the fill color, as a string.
def square(x, y, width, color):
turtle.penup() # Raise the pen
turtle.goto(x, y) # Move to the specified location
turtle.fillcolor(color) # Set the fill color
turtle.pendown() # Lower the pen
turtle.begin_fill() # Start filling
for count in range(4): # Draw a square
turtle.forward(width)
turtle.left(90)
turtle.end_fill() # End filling
# Call the main function.
#
# Original Code Commented out
# Invalid
# -------------------
#
# if _ _name_ _ == '_ _main_ _':
#
# ------------------------
# Corrected code below
if __name__ == '_ _main_ _':
main()