Question

Task2. The second task is to draw digits of your ID number centered and evenly spaced...

Task2. The second task is to draw digits of your ID number centered and evenly spaced out on
the screen using a pen color chosen by the user. The user should also input the choice of the
digit-style to draw.

by python
turtel graphics

my ID: 116182

Option 1: Using right-angled digit shapes (calculator-style) .
2. Option 2: Using a shape where the number of angles is equal to the digit .

use any of these options

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

from turtle import Turtle, Screen
BORDER = 1
BOX_WIDTH, BOX_HEIGHT = 6, 10 # letter width and height
WIDTH, HEIGHT = BOX_WIDTH - BORDER * 2, BOX_HEIGHT - BORDER * 2 # letter size

def draw1():
t.penup()
t.pencolor('blue')
t.right(90)
t.forward(WIDTH/2)
t.left(90)
t.pendown()
t.forward(HEIGHT)
  
def draw6():
t.penup()
  
t.forward(HEIGHT)
t.right(90)
t.forward(WIDTH)
t.pendown()
t.backward(WIDTH)
t.right(90)
t.forward(HEIGHT)
t.left(90)
t.forward(WIDTH)
t.left(90)
t.forward(HEIGHT/2)
t.left(90)
t.forward(WIDTH)
  
def draw8():
t.penup()
t.forward(HEIGHT)
t.right(90)
t.forward(WIDTH)
t.pendown()
t.backward(WIDTH)
t.right(90)
t.forward(HEIGHT)
t.left(90)
t.forward(WIDTH)
t.left(90)
t.forward(HEIGHT/2)
t.left(90)
t.forward(WIDTH)
t.penup()
t.backward(WIDTH)
t.pendown()
t.right(90)
t.forward(HEIGHT/2)
  
def draw2():
t.penup()
t.forward(HEIGHT)
t.right(90)
t.pendown()
t.forward(WIDTH)
t.right(90)
t.forward(HEIGHT/2)
t.right(90)
t.forward(WIDTH)
t.left(90)
t.forward(HEIGHT/2)
t.left(90)
t.forward(WIDTH)
  
wn = Screen()
wn.setup(1000, 600)
wn.title("My ID: {}".format("116182"))
wn.setworldcoordinates(0, 0, BOX_WIDTH * 6, BOX_HEIGHT)


t = Turtle()
t.speed(0)
#t.hideturtle()


t.penup()
t.goto(0* BOX_WIDTH + BORDER, BORDER)
t.setheading(90)
t.pendown()
draw1()


t.penup()
t.goto(1* BOX_WIDTH + BORDER, BORDER)
t.setheading(90)
t.pendown()
draw1()

t.penup()
t.goto(2* BOX_WIDTH + BORDER, BORDER)
t.setheading(90)
t.pendown()
draw6()

t.penup()
t.goto(3* BOX_WIDTH + BORDER, BORDER)
t.setheading(90)
t.pendown()
draw1()

t.penup()
t.goto(4* BOX_WIDTH + BORDER, BORDER)
t.setheading(90)
t.pendown()
draw8()

t.penup()
t.goto(5* BOX_WIDTH + BORDER, BORDER)
t.setheading(90)
t.pendown()
draw2()

wn.exitonclick()

  
Code Snippet

 from turtle import Turtle, Screen BORDER = 1 BOX_WIDTH, BOX_HEIGHT = 6, 10 # letter width and height WIDTH, HEIGHT = BOX_WIDTH - BORDER * 2, BOX_HEIGHT - BORDER * 2 # letter size def draw1(): t.penup() t.pencolor('blue') t.right(90) t.forward(WIDTH/2) t.left(90) t.pendown() t.forward(HEIGHT) def draw6(): t.penup() t.forward(HEIGHT) t.right(90) t.forward(WIDTH) t.pendown() t.backward(WIDTH) t.right(90) t.forward(HEIGHT) t.left(90) t.forward(WIDTH) t.left(90) t.forward(HEIGHT/2) t.left(90) t.forward(WIDTH) def draw8(): t.penup() t.forward(HEIGHT) t.right(90) t.forward(WIDTH) t.pendown() t.backward(WIDTH) t.right(90) t.forward(HEIGHT) t.left(90) t.forward(WIDTH) t.left(90) t.forward(HEIGHT/2) t.left(90) t.forward(WIDTH) t.penup() t.backward(WIDTH) t.pendown() t.right(90) t.forward(HEIGHT/2) def draw2(): t.penup() t.forward(HEIGHT) t.right(90) t.pendown() t.forward(WIDTH) t.right(90) t.forward(HEIGHT/2) t.right(90) t.forward(WIDTH) t.left(90) t.forward(HEIGHT/2) t.left(90) t.forward(WIDTH) wn = Screen() wn.setup(1000, 600) wn.title("My ID: {}".format("116182")) wn.setworldcoordinates(0, 0, BOX_WIDTH * 6, BOX_HEIGHT) t = Turtle() t.speed(0) #t.hideturtle() t.penup() t.goto(0* BOX_WIDTH + BORDER, BORDER) t.setheading(90) t.pendown() draw1() t.penup() t.goto(1* BOX_WIDTH + BORDER, BORDER) t.setheading(90) t.pendown() draw1() t.penup() t.goto(2* BOX_WIDTH + BORDER, BORDER) t.setheading(90) t.pendown() draw6() t.penup() t.goto(3* BOX_WIDTH + BORDER, BORDER) t.setheading(90) t.pendown() draw1() t.penup() t.goto(4* BOX_WIDTH + BORDER, BORDER) t.setheading(90) t.pendown() draw8() t.penup() t.goto(5* BOX_WIDTH + BORDER, BORDER) t.setheading(90) t.pendown() draw2() wn.exitonclick() 

Screenshot of my editor

- O x La id.py - C:/Users/AKIB/AppData/local/Programs/Python/Python38-32/id.py (3.8.0)* File Edit Format Run Options Window H

- O X www o o La id.py - C:/Users/AKIB/AppData/Local/Programs/Python/Python38-32/id.py (3.8.0)* File Edit Format Run Options

- O X Lè *id.py - C:/Users/AKIB/AppData/Local/Programs/Python/Python38-32/id.py (3.8.0)* File Edit Format Run Options Window

Output:

My ID: 116182 – O X

Add a comment
Know the answer?
Add Answer to:
Task2. The second task is to draw digits of your ID number centered and evenly spaced...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Task 1 Draw a flowchart that presents the steps of the algorithm required to perform the task spe...

    Task 1 Draw a flowchart that presents the steps of the algorithm required to perform the task specified. You can draw the flowcharts with a pen/pencil on a piece of paper and scan it for submission. Please ensure that the scanned file and your handwriting are clear and legible. However, it is preferable to draw flowcharts using a drawing software. Here are links to some free drawing tools https://www.draw.io/ www.lucidchart.com http://dia-installer.de/ https://pencil.evolus.vn/ ---------------------------------DON'T NEED THE PYTHON CODE... JUST THE ALGORITHM...

  • Game Description: Most of you have played a very interesting game “Snake” on your old Nokia...

    Game Description: Most of you have played a very interesting game “Snake” on your old Nokia phones (Black & White). Now it is your time to create it with more interesting colors and features. When the game is started a snake is controlled by up, down, left and right keys to eat food which appears on random locations. By eating food snake’s length increases one unit and player’s score increases by 5 points. Food disappears after 15 seconds and appears...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT