69.8k views
2 votes
a) Before writing any code, you should go through a design process. Try to do so carefully – either follow a top-down approach, a full bottom-up approach, or some combination. But, in any case, you should come up with a list of functions you plan to implement, each with its own clear purpose. a. Create a document that outlines all the functions you will create, including a purpose for each, stating what the function does, and any parameters it has. The purpose for each function can become its docstring b) After you have written a description of your program, including the planned functions, go ahead and write code for each function. Be sure to create a docstring for each function. Turn in your program and the design document you created beforehand. Challenge: See if you can create a program so that the lines are drawn

User Ardalan
by
4.7k points

1 Answer

3 votes

Answer:

See Explaination

Step-by-step explanation:

import turtle

def drawLine(x,y,height):

'''

method to draw a vertical line from x,y with given height

'''

turtle.up()

turtle.goto(x,y)

turtle.down()

turtle.goto(x,y-height)

def drawSet(x,y,height):

'''

method to draw a full set of tally marks

'''

temp = x

#drawing 5 vertical lines

for j in range(4):

drawLine(temp,y,height)

temp+=20

#drawing a line crossing all previous lines

turtle.up()

turtle.goto(x-5,y-height/2)

turtle.down()

turtle.goto(temp-15,y-height/4)

def drawPartialSet(x,y,height,count):

'''

method to draw an incomplete set (less than 5 tally marks)

'''

temp = x

for j in range(count):

drawLine(temp,y,height)

temp+=20

#getting number

num=int(input('Enter the number: '))

#finding number of complete sets

sets=num//5

#finding number of incomplete sets

extra=num%5

#setting up turtle

turtle.setup(width=500,height=500)

turtle.pensize(5)

turtle.speed(0) #max speed

#starting x, y coordinates

x=-240

y=250

line_height=80 #height of one tally line

#drawing all complete sets

for i in range(1,sets+1):

drawSet(x,y,line_height)

x+=line_height

if i%5==0:

#moving to next line after every 5 sets

x=-240

y-=line_height+50

#drawing extra sets if exist

if extra>0:

drawPartialSet(x,y,line_height,extra)

turtle.ht() #hide turtle

turtle.done() #finish drawing

User Daniele Faugiana
by
5.4k points