generated from mwc/lab_iteration
resubmitting
This commit is contained in:
parent
b1a1d04b15
commit
9a36d12b15
Binary file not shown.
Binary file not shown.
|
@ -9,15 +9,18 @@ def print_all_numbers(maximum):
|
|||
|
||||
def print_even_numbers(maximum):
|
||||
"Prints all even integers from 0 to maximum."
|
||||
pass
|
||||
for number in range(0, maximum, 2):
|
||||
print(number)
|
||||
|
||||
def print_odd_numbers(maximum):
|
||||
"Prints all odd integers from 0 to maximum."
|
||||
pass
|
||||
for number in range(1, maximum, 2):
|
||||
print(number)
|
||||
|
||||
def print_multiples_of_five(maximum):
|
||||
"Prints all integers which are multiples of five from 0 to maximum."
|
||||
pass
|
||||
for number in range(0, maximum, 5):
|
||||
print(number)
|
||||
|
||||
chosen_maximum = int(input("Choose a number: "))
|
||||
print(f"All numbers from 0 to {chosen_maximum}")
|
||||
|
|
12
square.py
12
square.py
|
@ -1,14 +1,10 @@
|
|||
from turtle import *
|
||||
|
||||
def square(side_length):
|
||||
forward(side_length)
|
||||
right(90)
|
||||
forward(side_length)
|
||||
right(90)
|
||||
forward(side_length)
|
||||
right(90)
|
||||
forward(side_length)
|
||||
right(90)
|
||||
sides = [1, 2, 3, 4]
|
||||
for side in sides:
|
||||
forward(side_length)
|
||||
right(90)
|
||||
|
||||
sizes = [20, 40, 60, 80, 100]
|
||||
for size in sizes:
|
||||
|
|
22
tile.py
22
tile.py
|
@ -1,23 +1,23 @@
|
|||
from turtle import *
|
||||
import math
|
||||
|
||||
def draw_tile(size):
|
||||
"Draws one tile, which can be repeated to form a pattern."
|
||||
draw_tile_outline(size)
|
||||
draw_squiggle(size)
|
||||
draw_zigzag(size)
|
||||
|
||||
def draw_tile_outline(size):
|
||||
pencolor("#dddddd")
|
||||
square(size)
|
||||
|
||||
def draw_squiggle(size):
|
||||
def draw_zigzag(size):
|
||||
forward(size/4)
|
||||
pencolor("black")
|
||||
left(45)
|
||||
forward(math.sqrt(2)*size/2)
|
||||
left(90)
|
||||
quarter_arc_right(size/4)
|
||||
quarter_arc_left(size/4)
|
||||
quarter_arc_left(size/4)
|
||||
quarter_arc_right(size/4)
|
||||
left(90)
|
||||
forward(math.sqrt(2)*size/2)
|
||||
left(45)
|
||||
fly(size/4)
|
||||
left(90)
|
||||
fly(size)
|
||||
|
@ -34,11 +34,3 @@ def square(size):
|
|||
for side in range(4):
|
||||
forward(size)
|
||||
left(90)
|
||||
|
||||
def quarter_arc_right(radius):
|
||||
"Draws a quarter of an arc, turning to the right."
|
||||
circle(-radius, 90)
|
||||
|
||||
def quarter_arc_left(radius):
|
||||
"Draws a quarter of an arc, turning to the left."
|
||||
circle(radius, 90)
|
||||
|
|
14
tile_grid.py
14
tile_grid.py
|
@ -10,7 +10,19 @@ from tile import fly
|
|||
def draw_tile_grid(width, height, tile_size, tile_function):
|
||||
"""Draws a (width x height) grid, with tile_function drawn on each tile.
|
||||
|
||||
(Your explanation here.)
|
||||
(The width, height, and tile_size are input when running the program
|
||||
from the terminal. The tile_function determines the pattern drawn on the
|
||||
tile, and when the tile_function argument is called, it passes and runs
|
||||
the function draw_tile from tile.py, because it is the last function it
|
||||
encountered...?
|
||||
|
||||
The "for y in range(height):" calls a loop determined by the the number of
|
||||
rows indicated by the height. The "for x in range(width):" calls a loop
|
||||
determined by the number of columns indicated by the width. The program
|
||||
draws a complete row, then stops drawing and returns to the horizontal
|
||||
starting point and moves up one tile length. It returns to the origin at
|
||||
the very end.)
|
||||
|
||||
"""
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
|
|
Loading…
Reference in New Issue