Why is there a different output in turtle and in console


#1

Here’s my code: I was wondering why I get different outputs in my console and in the turtle module. how would I fix this so that the indentation in the turtle window is correct and lines up in the same column?

import turtle

y = 180
for i in range(1, 9 + 1):
string = “”
#string += str(i) + " |"

for j in range(1, 9 + 1):
    string += format(i * j, ">4d")

if i > 0:
    print(string)

turtle.penup()
turtle.goto(-40, y)
turtle.pendown()
turtle.write(string, font=("Arial", 20, "normal"))
y -= 20

turtle.hideturtle()
turtle.done()


#2

Ignore the comment. The only thing that matters is the outputs.


#3

Please make sure that your code is intact. It should be possible to copy it and run it without any modification.

I’m not sure what your different outputs are. You’ll have to show/tell.

What comment should we ignore? The commented out line in the code? You can edit your post and remove it instead.

Are you trying to align numbers? You can accomplish that by making sure each number has the same width, which involves adding spaces where they are not wide enough. (padding)
Another requirement is to use a fixed-width font. A number 1 should be as wide as the number 0, for example.


#4

How would I make each character a fixed width font?


#5

Change to a font with that property, for example inconsolata


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.