Python challenges

Task 1)

import turtle
def main():

    scr=turtle.Screen()
    scr.title(‘Square Demo’)
    bailey=turtle.Turtle()

    for sides in  range (0,4):
        bailey.fd(50)
        bailey.rt(90)

    #Here’s the line that stops the crash!
    turtle.getscreen()._root.mainloop()

if __name__ == ‘__main__’:
    main()


 

Task 2)

import turtle

def main():

    scr=turtle.Screen()
    scr.title(‘Triangle Demo’)
    bailey = turtle.Turtle()

    bailey.rt(30)
    bailey.fd(50)
    bailey.rt(120)
    bailey.fd(50)
    bailey.rt(120)
    bailey.fd(50)

    turtle.getscreen()._root.mainloop()

if __name__ == ‘__main__’:
    main()


 

Task 3)

import turtle

def main():

    scr=turtle.Screen()
    scr.title(‘Circle Demo’)
    bailey = turtle.Turtle()

    bailey.speed(20)

    for x in range(0,360):
        bailey.fd(x)
        bailey.rt(360-x)

    turtle.getscreen()._root.mainloop()

if __name__ == ‘__main__’:
    main()


 

Task 4)

import turtle
bailey=turtle.Turtle()

def drawSquare(width,height):
        for x in range(0,2):
            bailey.fd(width)
            bailey.rt(90)
            bailey.fd(height)
            bailey.rt(90)

def main():

    drawSquare(int(raw_input(‘width:’)), int(raw_input(‘height:’)))
    turtle.getscreen()._root.mainloop()

if __name__ == ‘__main__’:
    main()


 

Task 5)

import turtle
bailey=turtle.Turtle()

def drawSquare(width,height):
        for x in range(0,2):
            bailey.fd(width)
            bailey.rt(90)
            bailey.fd(height)
            bailey.rt(90)

def main():

    drawSquare(int(raw_input(‘width:’)), int(raw_input(‘height:’)))
    turtle.getscreen()._root.mainloop()

if __name__ == ‘__main__’:
    main()