Skip to content

Commit 0332598

Browse files
comp151 s25 lab2
1 parent d6c6ee0 commit 0332598

2 files changed

Lines changed: 63 additions & 2 deletions

File tree

_courses/comp151/s25.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,12 @@ which they are listed below.
261261
| Fri 01/31 | Debugging Exercises | FOPP 3.1-3.8 |
262262
|--------------------------------+---------------------------------------------+-------------------------------------------------|
263263
| Mon 02/03 (Week 3) | Modules; Intro to Turtle | FOPP 4.1-4.4 |
264-
| **Mon 02/03 (lab)** | Lab 02: Input-Compute-Ouput | Homework 2 out |
264+
| **Mon 02/03 (lab)** | [Lab 02: Turtle](lab02) | Homework 2 out |
265265
| Wed 02/05 | Turtle, OO, and `for` loops | FOPP 5 |
266266
| Fri 02/07 | Guest Speaker about Cybersecurity | |
267267
|--------------------------------+---------------------------------------------+-------------------------------------------------|
268268
| Mon 02/10 (Week 4) | Sequences | FOPP 6.1-6.5 |
269-
| **Mon 02/10 (lab)** | [Lab 03: Turtle](lab03) | (No Homework) |
269+
| **Mon 02/10 (lab)** | Lab 03: TBD | (No Homework) |
270270
| Wed 02/12 | Exam 1 Review | |
271271
| Fri 02/14 | Exam 1 | |
272272
|--------------------------------+---------------------------------------------+-------------------------------------------------|

_courses/comp151/s25/lab02.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
layout: class
3+
title: "COMP 151, Spring 2024, Lab 03"
4+
semester: s24
5+
---
6+
7+
## Lab 03: Experiments with Turtle
8+
9+
Our book has some nice content using `turtle`, such as [this
10+
activity](https://runestone.academy/ns/books/published/monmouth-comp151-spring25/Projects/drawing_a_circle.html#drawing-a-circle),
11+
but doesn't involve enough problem solving with it.
12+
13+
So, I created a custom lab which involves `turtle`, `random`, and just
14+
a bit of problem solving.
15+
16+
### Instructions
17+
18+
Choose any code block from the book. Something from the [Drawing a
19+
Circle with the
20+
Turtle](https://runestone.academy/ns/books/published/monmouth-comp151-spring25/Projects/drawing_a_circle.html#drawing-a-circle)
21+
activity would be fitting, but it doesn't really matter.
22+
23+
You need to write code that satisfies the following requirements:
24+
25+
- Randomly choose a number between 1 and 10 (inclusive), call it $n$.
26+
- In a loop, create $n$ turtles.
27+
- For each turtle:
28+
- Assign them a random color.
29+
- Choose a random radius from 50, 75, 100, 125, 150
30+
- Have the turtle draw a circle with that radius and color
31+
- At the end, print total and average distance travelled
32+
33+
**Note**: Each turtle should choose its color and radius independently
34+
of the other turtles.
35+
36+
When you are done, raise your hand and show me your code.
37+
38+
### Hints
39+
40+
- In addition to our book's chapters on `turtle` and `random`, you
41+
will probably need to skim Python's official documentation for the
42+
[`turtle` module](https://docs.python.org/3/library/turtle.html) and
43+
for the [`random`
44+
module](https://docs.python.org/3/library/random.html).
45+
- To draw a circle, learn about [`turtle`'s `circle`
46+
method](https://docs.python.org/3/library/turtle.html#turtle.circle).
47+
- You will need just a little bit of [chapter
48+
6](https://runestone.academy/ns/books/published/monmouth-comp151-spring25/Sequences/toctree.html)
49+
content to create a list of possible radii, and maybe a list of
50+
possible colors. Luckily, we'll cover enough of that right before
51+
lab.
52+
- To choose an item randomly from a list, learn about [`random`'s
53+
`choice`
54+
method](https://docs.python.org/3/library/random.html#random.choice).
55+
- To figure out the area a turtle traveled, you'll need to use the
56+
formula for the circumference of a circle.
57+
- To compute the **total** distance all turtles have traveled, you'll
58+
need to have a separate variable that starts at 0 and gets added to
59+
inside your loop. This is your first example of the *accumulator*
60+
pattern. Don't be afraid to ask for help about this.
61+

0 commit comments

Comments
 (0)