ASCII character table

For students who are taking a programming course, may be restricted in what they can use, or have other unusual limitations on solving their task.

ASCII character table

Postby nzieno » Thu Sep 29, 2016 12:17 am

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
   
 
nzieno
 
Posts: 16
Joined: Fri Jul 29, 2016 12:38 am

Re: ASCII character table

Postby Kebap » Thu Sep 29, 2016 1:12 pm

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.
Due to the reasons discussed here we are moving to python-forum.net on October 1, 2016.

This forum will be closed. Please create an account at the new site to continue discussion.

IRC://irc.freenode.net/python-forum
Kebap
 
Posts: 689
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: ASCII character table

Postby nzieno » Thu Sep 29, 2016 10:35 pm

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
nzieno
 
Posts: 16
Joined: Fri Jul 29, 2016 12:38 am

Re: ASCII character table

Postby nzieno » Fri Sep 30, 2016 1:25 pm

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 
               
nzieno
 
Posts: 16
Joined: Fri Jul 29, 2016 12:38 am


Return to Homework

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests