Feel free to take a look at this tutorial in advance, but since attendance is required this first week so you can meet your team, you do not need to actually work on it until class on Wednesday.

Submitting

Regardless of how you choose to complete the assignment, you MUST submit the file you worked on to Canvas. Do that BEFORE LEAVING THE ROOM if you are in-person.

IF YOU ARE SUBMITTING REMOTELY

This is not an option for this first tutorial. Come meet your tutorial team. In future weeks, you can choose to do this and your file will be graded for completeness and correctness.

IF YOU ARE IN CLASS OR AT AN ALT TUTORIAL

Then your file will be graded for participation (i.e. it’s okay if you haven’t finished the entire thing because you may have spent time asking a question; helping a friend; etc.) along with what we call a ‘peer review.’ Find one other person in your group that is finished and peer review each other’s work. Here are the things to check:

  1. Does their code look readable and neat?
  2. Can you understand what their code does by reading it?
  3. How was their solution different from yours (if at all)?
  4. Does their program run and generate the correct results?

Once you’ve debriefed, both of you should fill out this attendance Google Form. NOTE: You will need the NetID of the person's whose code you reviewed. This form will only be available near the end of the tutorial session.

You’re free to go after you’re finished and submitted both your .py and Google Form, though we hope that you might consider sticking around and helping others in your group.


Getting Started

Our objectives for this assignment are:

  1. Storing data in variables
  2. Doing basic math in Python
  3. Understanding data types
  4. Calling basic functions

Part 0. Meet Your Group

A first step to building any community is to introduce yourselves!

Once in your group, figure out who has the earliest birthday (i.e. January 1st is the earliest possible birthday). This person will go first and introduce themselves with the following:

Note, your group will have a Peer Mentor or TA assigned to it and they will come introduce themselves as well! They’ll be easy to identify as they’ll all have name tags! Because PMs are assigned to multiple groups, they may not be present for all the intros and might ask you to quickly go around and say names again.

Once you’ve all had a chance to introduce yourselves, you can get started on your tutorial!


Part 1. Get Your Files Organized

Create the folder organizational structure recommended in class during Monday’s Lecture.

cs110
    |-- homeworks
    │   |-- hw0
    │   |-- hw1
    |   ...
    |-- lectures
    |   -- lecture00
    │   -- lecture01
    │   -- lecture02
    │   ...
    |-- tutorials
        ...

Part 2. Create two Python files and Write Some Programs

When you’re done, open IDLE and create a new python file (go to File menu > “New File”). This should open a blank document. Then save this blank document as grade_calculator.py (File menu > “Save as…”), and put it inside of your cs110 > tutorials > tutorial1 folder (You’ll need to make that tutorial1 folder just like you did with the three top-level folders).

In this newly created grade_calculator.py file, you’re going to write a program to calculate your grade in our class:


Storing Data in Variables

Hint! We'll help you on this first one in Python. Copy and paste the below into your file:

miniquizzes = 100

In plain English this says: "Please assign the value 100 to the variable named miniquizzes".

Make sure to run your program by going to the Run menu at the top of the screen and selecting Run Module.... If you don’t see any red error text, that means your program successfully ran! Since we haven’t asked Python to actually output anything yet (we’ve only asked it to remember some numbers) we won’t see any output.

How do I turn on line numbers? Ever notice that in my IDLE you can see a number before each line? You can make IDLE do the same for you by going to the OPTIONS menu and selecting Show line numbers.

Accessing Data in Variables

Accessing data stored in a variable is as easy as using the name of the variable in another line of our program. Python will then see this name and lookup what value you’ve asked it to remember is stored inside that container.

Now let’s actually calculate the course average for these 5 inputs. Recall from our syllabus that your grade is broken down in the following categories.

Tutorials 10%
Mini-Quizzes 5%
Exercises 25%
2 Projects 25%
3 Quizzes 35%
What's a weighted average? When you see a weighted average like this, it means that different assignments are weighted by their respective percentages (i.e. a category with a higher weight means it constitutes a larger part of your final grade). To calculate the final weighted average, we take the decimal form of the weight for each category and multiply that weight by the average for that category, after doing that for each category, we add up all of those calculations and that gives us our final grade.

For example, to calculate the part of your grade determined by the tutorials, we would take the tutorial weight in decimal form (10% -> 0.1) and multiply it by the overall tutorial score. Then you’d repeat this process for each different assignment category. Imagine you got a 100 for all 5 categories, that would mean your final grade would be calculated by saying:

Grade Calculation Equation (0.10 * 100) + (0.05 * 100) + (0.25 * 100) + (0.25 * 100) + (0.35 * 100)

However, we need to use the grades that are stored in the variables we created earlier. For example, the overall tutorial score is scored in the variable tutorials. To access the actual value of that variable, we simply use its name (tutorials) in place of an actual number. For instance, to calculate the part of your grade determined by the tutorials, in Python we’d say:

(0.10 * tutorials)

That says multiply 0.10 with whatever value is stored in the variable tutorials. When you go to run your file, Python will then lookup whatever number is stored in that container and use it for the calculation.


Using the print Function

Well that was a let down…nothing got outputted!

Remember: computers don’t do anything we don’t ask of them. Because we didn’t ask Python to output the value of grade, when we run our program…it doesn’t output the result of the calculation.

Add a new line to your program that calls the print function with an argument of the variable grade. Now try running your program again. If everything is correct with your calculator, you should see 94 printed out in the Interpreter (>>>) Window since we’ve asked our program to output the value stored in that variable.


Using the input Function

What we’ve done now is essentially asked the computer to remember the average of our scores across these 5 different types of assignments and then calculate the resulting course average. Now, these variables are currently “set in stone” or hardcoded to be particular numbers. In other words, every time we run this program, it will always use those exact same numbers for the grade calculation. While that’s fine when calculating our grade, what if we wanted to be able to send our program to a friend in the class so they could calculate their grade without modifying the code?

Using the input function, we can tell Python to ask the person running the program to type a number using keyboard. The input function takes a string as an argument which represents the prompt Python shows the user and returns a string of whatever the person typed in.

Hint! In other words...

quizzes = input("Please enter your quiz average:")

In plain English this says: "Please assign the value of whatever we get back from calling the input function, to the variable named quizzes".

Did it work? No? Uh oh. Let’s think about why by using the error we got as a clue:

Traceback (most recent call last):
  File "/Users/username/Desktop/tutorial1/grade_calculator.py", line 7, in <module>
    grade = (0.10 * tutorials) + (0.05 * miniquizzes) + (0.25 * homeworks) + (0.25 * projects) + (0.35 * quizzes)
TypeError: can't multiply sequence by non-int of type 'float'

This error says it occurs on the line where we calculate the final grade and that it says it’s a TypeError. In other words, Python says you asked me to multiply the value stored in this variable…but it’s not a number! Why might that be? Well remember that the input function returns a str or string. But the * operator only knows how to deal with numbers! That means we need to convert or cast the value we get back from input from a str to an int (or integer).

To convert the quizzes variable to an integer we need to use the int function which accepts any argument and will try its best to return an int (integer) from that argument.

There’s two (easy) ways you can implement this in your program.

  1. You could add a new line after the line that says quizzes = ... that says quizzes = int(quizzes) – in other words, you’d ask Python to replace the existing quizzes variable with the result of converting whatever is currently in the quizzes variable to an int.
  2. You could change the calculation of grade to use int(quizzes) rather than just quizzes – this essentially tells Python to not modify the original variable but to instead just convert the value for the purposes of the calculation.

Pick an approach and implement in your program. Finally Run your program again and make sure you get the expected output given whatever you typed in! In fact…run it twice with two different numeric pieces of data (note, it will only work with whole numbers) and make sure you get two different final grades!


Part 3. Turtle Time

This time, rather than starting from scratch, we’re going to give you a template to work in. Click the big purple button below to download the file turtorial.py. Move that downloaded file into your tutorial1 folder and go ahead and open it in IDLE.

Tutorial Starter File

The file isn't downloading. What do I do? Some Web Browsers don't automatically download .py files. If this happens to use, just "right click" (or hold down the CONTROL key on your keyboard and click) on the button and select "Save linked file as..." or "Download linked file..." (the exact wording will depend on your browser - i.e. Chrome, Safari, Firefox, etc.)
Turtle Function Cheatsheet
### TURTLE CHEATSHEET ###############################################
# Pretend we have a turtle named: turtle_0

# If we want turtle_0 to go forward 100 steps we just say:
forward(turtle_0, 100)

# If we want turtle_0 to turn left or right 90 degrees, we just say:
left_turn(turtle_0, 90)
right_turn(turtle_0, 90)

# If we want to turn turtle_0 around, we'd just turn 180 degrees!
right_turn(turtle_0, 180)

# If we want turtle_0 to change the color of its pen:
change_pen_color(turtle_0, "green")

# If we want to make a new turtle at a specific x, y coordinate, we use the optional

# arguments to the MyTurtle Function like so

turtle_0 = MyTurtle(x = 100, y = 100)
# (If you leave those out, it will default to 0, 0)

Now here’s your job:


Some Pro Tips