This week’s assignment is focused on writing simple programs just like the tutorial. It does not ask you to write any functions of your own (which is the focus of our Friday lecture this week).
By the end of this assignment you should be able to:
- Call some basic turtle functions
- Store data in variables
- Identify a data type
- Doing basic math in Python
- Use the
input
function - Use the
print
function
Part 0. Download the Template File
First create a new folder in your CS 110 folder, inside the exercises
folder called exercise1
(or some variation).
Then download the starter file by clicking on the big button below.
Move the downloaded file into your new exercise1
folder and rename it something like exercise_1.py
so you don’t accidentally get it confused with any other versions.
Part 1. More Turtle Programming
- Open up exercise_1.py file that you just saved in your exercise1 folder and open it with IDLE (if you’re on a Mac, you can double-click on it; if you’re on a Windows computer, it’s often easier to first open IDLE, then click on the
File
menu thenOpen
…). If you’d like to enable double-clicking on Windows, you can follow these instructions. - You should now see some python code. Click anywhere inside that file so that your cursor is now in that window.
- Hit F5 (if you’re on a Mac, hit the fn key and then F5). As an alternative to F5, you can also go to the Run menu and select Run Module. Your code will then be executed by the Python interpreter. Right now, it doesn’t do much, but using just
forward
,left_turn
, andright_turn
we can make some cool stuff!
Please complete the following exercises by editing the exercise_1.py file using IDLE:
- Teach
turtle_1
to draw a square with sides of length 100. - Teach
turtle_2
to draw a green rectangle with sides of length 100 and 120. - Teach
turtle_3
to draw a red equilateral triangle (3 equal length sides) with side length 100. - Teach
turtle_4
to draw a house (a square of sides of 100 with an equilateral triangle with sides of 100 on top). Color(s) are up to you.
Hint: You can’t just paste the two solutions together. Think about which direction your turtle is facing when it stops and starts drawing! It might help to play out the turtle’s motion yourself!
- Teach
turtle_5
to draw something interesting! It needs to use at least two pen colors and needs to include at least 3 rotations and 3 forward commands.
Remember: YOU MUST USE EXACTLY THESE TURTLE NAMES, just like we used
shelly
in the tutorial.
After completing all 5 exercises, your screen should look something like this:
Part 2. Some Data Programs
Next we’ll focus on some data programming toward the bottom of the exercise_1.py
file.
Activity 2.1. Write a program that computes and prints the result of
(The answer is roughly 0.1017). Store the result of this equation in a variable called question_1
and then print it out.
Activity 2.2. Text Entry
Write a program to ask the user to enter their name. Make a message that says “hi” to them and store the entire message in a variable called question_2
and then print it out.
For example, this is what you would see if you used my name (notice we use a prompt
):
Enter a name:Connor # prompt the user for a name (not necessarily Connor)
Hi Connor! # output a sentence that says hi (make sure there's a space)
Note: when your program runs, it should look exactly like the above with whatever name you type in.
Activity 2.3. Numeric entry
Write a program that asks the user for a distance in kilometers and converts it to miles. There are 0.62 miles in a kilometer. You only need to worry about whole number weight entries. Store just the converted value in a variable called question_3
and then print it out in a nice message like the below.
Enter distance in km:5 # prompt the user for a distance in km
5 kilometers is approximately 3.1 miles. # output the result
Note: when your program runs, it should look exactly like the above with whatever weight you type in. In some circumstances, you might get a number with a huge number of decimal places – that’s fine.
Activity 2.4. Combining both ideas
Write a program that asks the user to type in a word and then tell the user how many letters are in that word. Store just the number of letters of the typed-in word in a variable called question_4
and then print it out in a nice message like the below.
For example:
Enter a word:supercalifragilisticexpialidocious # prompt the user for a word
There are 34 letters in that word. # output the result
Note: when your program runs, it should look exactly like the above with whatever name you type in
Turning it in
Most of the Exercises in this class will be graded via an autograder – a program, written in Python, that will run your program and test it to see if it meets all the expectations of the assignment.
This means that you must carefully read each assignment description and follow it exactly. If your assignment does not satisfy the requirements in any way (even if you think it’s small and inconsequential) you will receive points off (or in the worst case, not receive any points at all). For this assignment, you should make sure your turtle drawing looks like the one featured above and that the math calculations produce the expected output as specified.
For this assignment, you will upload your exercise.py
file to the assignment on Canvas. DO NOT UPLOAD ANY OTHER FILES. Once you’ve submitted your file to Canvas, you’re done! You do not need to add your netid
to the file like we did last week.
Note: The autograder won’t start checking assignments until late on Monday.
Submission Details
Remember, close IDLE before you submit to ensure that you’ve saved your latest work. Once you’ve successfully submitted you should receive feedback from the autograder in 30 or so minutes. If you fail one of the checks, you’re welcome to resubmit (up to the Canvas resubmit limit for that assignment). If you’re confused on how to fix one of the checks, then bring your submission and the test results to office hours!