Page 1 of 1

ASCII character table

PostPosted: Thu Sep 29, 2016 12:17 am
by nzieno
Write a program that displays the characters in the ASCII character table from ! to ~. Display ten characters per line. The characters are separated by exactly 1 space. This has to be done using turtle.

The problem I am having with this program is getting the characters into rows of 10 I can get the characters to print in rows but it just prints the same characters in each row. I can't seem to figure this one out. Any pointers would be greatly appreciated.

Code: Select all
     import turtle


y = 0                   
for j in range(10):       
   x = -100             
   for a in range(1):
    print(a, end = '')
    for b in range(33, 43):
         turtle.penup()     
         turtle.goto(x, y)
         turtle.pendown()
         turtle.write(chr(b))
         x += 10
   y += 15
   
 

Re: ASCII character table

PostPosted: Thu Sep 29, 2016 1:12 pm
by Kebap
Pointers? Okay. Try moving through the for-loops by yourself and keep track of how the value of each variable changes or does not change even though you might expect it to.

Re: ASCII character table

PostPosted: Thu Sep 29, 2016 10:35 pm
by nzieno
Code: Select all
    import turtle


y = 0                   
for j in range(10):       
   x = -100             
   for b in range(33, 126):
         turtle.penup()     
         turtle.goto(x, y)
         turtle.pendown()
         turtle.write(chr(b))
         x += 10
   y += 15
     


I had the range wrong in the second FOR this is the updated one

Re: ASCII character table

PostPosted: Fri Sep 30, 2016 1:25 pm
by nzieno
Finally got it
Code: Select all
    import turtle


y = 0                   
for j in range(10):       
   x = -100             
   for b in range(33, 43):
         turtle.penup()     
         turtle.goto(x, y)
         turtle.pendown()
         turtle.write(chr(b))
         x += 10
   y += 15
   break
y = 15
for c in range(1):
    x = -100
    for d in range(44, 54):
        turtle.penup()
        turtle.goto(x, y)
        turtle.pendown()
        turtle.write(chr(d))
        x += 10
    y += 15
    break
y = 30
for c in range(1):
    x = -100
    for e in range(55, 65):
        turtle.penup()
        turtle.goto(x, y)
        turtle.pendown()
        turtle.write(chr(e))
        x += 10
    y += 15
    break
y = 45
for c in range(1):
    x = -100
    for f in range(66, 76):
        turtle.penup()
        turtle.goto(x, y)
        turtle.pendown()
        turtle.write(chr(f))
        x += 10
    y += 15
    break
y = 60
for c in range(1):
    x = -100
    for g in range(77, 87):
        turtle.penup()
        turtle.goto(x, y)
        turtle.pendown()
        turtle.write(chr(g))
        x += 10
    y += 15
    break
y = 75
for c in range(1):
    x = -100
    for h in range(88, 98):
        turtle.penup()
        turtle.goto(x, y)
        turtle.pendown()
        turtle.write(chr(h))
        x += 10
    y += 15
    break
y = 90
for c in range(1):
    x = -100
    for g in range(99, 109):
        turtle.penup()
        turtle.goto(x, y)
        turtle.pendown()
        turtle.write(chr(g))
        x += 10
    y += 15
    break
y = 105
for c in range(1):
    x = -100
    for h in range(110, 120):
        turtle.penup()
        turtle.goto(x, y)
        turtle.pendown()
        turtle.write(chr(h))
        x += 10
    y += 15
    break
y = 120
for c in range(1):
    x = -100
    for i in range(121, 127):
        turtle.penup()
        turtle.goto(x, y)
        turtle.pendown()
        turtle.write(chr(i))
        x += 10
    y += 15
    break