#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0

    Question I need help with debugging beginer 14 years old help me pleease


    I cant get this to work. Im lost ant im 14 and takeing a python class.
    Code:
    from turtle import*
    
    # Function variables
    space_width = input("Enter a space widith: ") # Default value: 30
    letter_height = input("Enter a letter height: ") # Default value: 100
    letter_width = input("Enter a letter width: ") # Default value: 50
    pen_color = input("Enter a color name to set the pen color: ")
    pen_width = input("Enter a number from 1-10 to set the pen width: ")
    
    def draw_space():
        # Add a space 30 pixels wide.
        penup()
        forward(space_width)
        pendown()
    
    def move_turtle():
        # Pickup the turtle and move it to its starting location.
        penup()
        goto(-200, 100)
        pendown()
        draw_space()
    
    def draw_H():
        # Draws the left leg of the H.
        #The turtle starts at the bottom left of the letter, pointing right.
        left(90)
        forward(letter_height)
        #draw the bar of the H.
        #The turtle starts at the top of the left leg, pointing up.
        forward(-letter_height / 2)
        right(90)
        forward(letter_width)
        #Draw the right leg of the H.
        left(90)
        forward(letter_height / 2)
        forward(-letter_height)
        right(90)
        #The H is drawn.
        #The turtle is at the bottom right, pointing right.
        draw_space()
    
    def draw_E():
        # Draw an E.
        left(90)
        forward(letter_height)
        right(90)
        forward(letter_width)
        forward(-letter_width)
        right(90)
        forward(letter_height / 2)
        left(90)
        forward(letter_width)
        forward(-letter_width)
        right(90)
        forward(letter_height / 2)
        left(90)
        forward(letter_width)
        draw_space()
    
    def draw_L():
        # Draw the L
        left(90)
        forward(letter_height)
        forward(-letter_height)
        right(90)
        forward(letter_width)
        draw_space()
    
    def draw_O():
    # Draw the O.
        forward(letter_width)
        left(90)
        forward(letter_height)
        left(90)
        forward(letter_width)
        left(90)
        forward(letter_height)
        left(90)
        forward(letter_width)
        draw_space()
    
    color(pen_color)
    width(pen_width)
    move_turtle()
    draw_H()
    draw_E()
    draw_L()
    draw_L()
    draw_O()
    here is the output

    >>>
    Enter a space widith: 5
    Enter a letter height: 5
    Enter a letter width: 5
    Enter a color name to set the pen color: red
    Enter a number from 1-10 to set the pen width: 5
    Traceback (most recent call last):
    File "C:\Users\SystemAdministrator\Desktop\resources\section_3\hello_by_variables_assn.py", line 84, in <module>
    move_turtle()
    File "C:\Users\SystemAdministrator\Desktop\resources\section_3\hello_by_variables_assn.py", line 21, in move_turtle
    draw_space()
    File "C:\Users\SystemAdministrator\Desktop\resources\section_3\hello_by_variables_assn.py", line 13, in draw_space
    forward(space_width)
    File "<string>", line 1, in forward
    File "C:\Python32\lib\turtle.py", line 1637, in forward
    self._go(distance)
    File "C:\Python32\lib\turtle.py", line 1604, in _go
    ende = self._position + self._orient * distance
    File "C:\Python32\lib\turtle.py", line 257, in __mul__
    return Vec2D(self[0]*other, self[1]*other)
    TypeError: can't multiply sequence by non-int of type 'float'
    >>>
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,997
    Rep Power
    481
    You're using python 3, which is good.

    input() returns a string but you need integers.

    I use int(input('prompt'))

    I've written the default values into the prompts so the user has some idea reasonable values.

    Now the program works, and all you need to do is press return for the responses. A dummy can operate the program.

    Exercises:

    1) The try: except: statements are repetitive. Abhor duplicate code. Find a way to rewrite as a loop.

    2) Verify the named color.
    Code:
        raise TurtleGraphicsError("bad color string: %s" % str(color))
    turtle.TurtleGraphicsError: bad color string: chartreusese


    Code:
    from turtle import*
    
    # Function variables
    try:
        space_width = int(input("Enter a space width (default 30): "))
    except:
        space_width = 30
    
    try:
        letter_height = int(input("Enter a letter height (default 100): "))
    except:
        letter_height = 100
    
    try:
        letter_width = int(input("Enter a letter width (default 50): "))
    except:
        letter_width = 50
    
    pen_color = input("Enter a color name to set the pen color (default black): ")
    if not pen_color:                         # use more cleverness
        pen_color = 'black'
    
    try:
        pen_width = int(input("Enter a number from 1-10 to set the pen width (default 2): "))
    except:
        pen_width = 2
    
    def draw_space():
        # Add a space 30 pixels wide.
        penup()
        forward(space_width)
        pendown()
    
    def move_turtle():
        # Pickup the turtle and move it to its starting location.
        penup()
        goto(-200, 100)
        pendown()
        draw_space()
    
    def draw_H():
        # Draws the left leg of the H.
        #The turtle starts at the bottom left of the letter, pointing right.
        left(90)
        forward(letter_height)
        #draw the bar of the H.
        #The turtle starts at the top of the left leg, pointing up.
        forward(-letter_height / 2)
        right(90)
        forward(letter_width)
        #Draw the right leg of the H.
        left(90)
        forward(letter_height / 2)
        forward(-letter_height)
        right(90)
        #The H is drawn.
        #The turtle is at the bottom right, pointing right.
        draw_space()
    
    def draw_E():
        # Draw an E.
        left(90)
        forward(letter_height)
        right(90)
        forward(letter_width)
        forward(-letter_width)
        right(90)
        forward(letter_height / 2)
        left(90)
        forward(letter_width)
        forward(-letter_width)
        right(90)
        forward(letter_height / 2)
        left(90)
        forward(letter_width)
        draw_space()
    
    def draw_L():
        # Draw the L
        left(90)
        forward(letter_height)
        forward(-letter_height)
        right(90)
        forward(letter_width)
        draw_space()
    
    def draw_O():
    # Draw the O.
        forward(letter_width)
        left(90)
        forward(letter_height)
        left(90)
        forward(letter_width)
        left(90)
        forward(letter_height)
        left(90)
        forward(letter_width)
        draw_space()
    
    color(pen_color)
    width(pen_width)
    move_turtle()
    draw_H()
    draw_E()
    draw_L()
    draw_L()
    draw_O()
    Last edited by b49P23TIvg; December 13th, 2012 at 06:09 PM.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0
    thankyou so much!!!
    Originally Posted by b49P23TIvg
    You're using python 3, which is good.

    input() returns a string but you need integers.

    I use int(input('prompt'))

    I've written the default values into the prompts so the user has some idea reasonable values.

    Now the program works, and all you need to do is press return for the responses. A dummy can operate the program.

    Exercises:

    1) The try: except: statements are repetitive. Abhor duplicate code. Find a way to rewrite as a loop.

    2) Verify the named color.
    Code:
        raise TurtleGraphicsError("bad color string: %s" % str(color))
    turtle.TurtleGraphicsError: bad color string: chartreusese


    Code:
    from turtle import*
    
    # Function variables
    try:
        space_width = int(input("Enter a space width (default 30): "))
    except:
        space_width = 30
    
    try:
        letter_height = int(input("Enter a letter height (default 100): "))
    except:
        letter_height = 100
    
    try:
        letter_width = int(input("Enter a letter width (default 50): "))
    except:
        letter_width = 50
    
    pen_color = input("Enter a color name to set the pen color (default black): ")
    if not pen_color:                         # use more cleverness
        pen_color = 'black'
    
    try:
        pen_width = int(input("Enter a number from 1-10 to set the pen width (default 2): "))
    except:
        pen_width = 2
    
    def draw_space():
        # Add a space 30 pixels wide.
        penup()
        forward(space_width)
        pendown()
    
    def move_turtle():
        # Pickup the turtle and move it to its starting location.
        penup()
        goto(-200, 100)
        pendown()
        draw_space()
    
    def draw_H():
        # Draws the left leg of the H.
        #The turtle starts at the bottom left of the letter, pointing right.
        left(90)
        forward(letter_height)
        #draw the bar of the H.
        #The turtle starts at the top of the left leg, pointing up.
        forward(-letter_height / 2)
        right(90)
        forward(letter_width)
        #Draw the right leg of the H.
        left(90)
        forward(letter_height / 2)
        forward(-letter_height)
        right(90)
        #The H is drawn.
        #The turtle is at the bottom right, pointing right.
        draw_space()
    
    def draw_E():
        # Draw an E.
        left(90)
        forward(letter_height)
        right(90)
        forward(letter_width)
        forward(-letter_width)
        right(90)
        forward(letter_height / 2)
        left(90)
        forward(letter_width)
        forward(-letter_width)
        right(90)
        forward(letter_height / 2)
        left(90)
        forward(letter_width)
        draw_space()
    
    def draw_L():
        # Draw the L
        left(90)
        forward(letter_height)
        forward(-letter_height)
        right(90)
        forward(letter_width)
        draw_space()
    
    def draw_O():
    # Draw the O.
        forward(letter_width)
        left(90)
        forward(letter_height)
        left(90)
        forward(letter_width)
        left(90)
        forward(letter_height)
        left(90)
        forward(letter_width)
        draw_space()
    
    color(pen_color)
    width(pen_width)
    move_turtle()
    draw_H()
    draw_E()
    draw_L()
    draw_L()
    draw_O()

IMN logo majestic logo threadwatch logo seochat tools logo