Lab 2: A year with PythonΒΆ

In this lab, you're going to create a program that uses several variables and then you'll experiment with some additional assignment statetments.

Challenge Exercise 1: Your task is to write a program which computes the fraction of the year that you will spend working on Python for this course. To do that, we'll make the following assumptions:

  • The "time spent on Python" is defined as the amount of time that it is recommended for students to put into a course.
  • The recommended time to spend on a course is 3 hours outside of class for every hour inside class.
  • A normal semester includes 14 weeks, with 150 minutes of in-class time each week.
  • You can assume the year is a non-leap year, with 365 days.

Your program might start like this:

num_course_weeks = 14
in_class_minutes_per_week = 150
total_in_class_minutes = num_course_weeks * in_class_minutes_per_week

You should include an output statetment which prints the answer along with text that explains what the number is. For example, something like this:

And, that's actually the answer you should come up with if you make all the assumptions listed above and you do all the calculations correctly.

Here's what I'll be looking for in your solution:

  • A correct calculation (i.e., the number above or something very close to it should be output with some text)
  • Create at least two new variables with descriptive names
  • Use variables on both the left and right side of =. That is, use the values of your variables in computing values for other variables

When you have your solution ready, submit it to codePost for the Lab 2: A year with Python assignment.

Exercise 2: Run the following code at the interactive shell, observe the output, and reflect on the questions below.

my_variable = 5
my_variable = my_variable + 1
print(my_variable)
  • Can you put a variable on both the left and right side of an assignment statement?
  • Why might you want to do that?

Exercise 3: Run the following code at the interactive shell, observe the output, and reflect on the questions below.

my_variable = 5
my_variable += 1
print(my_variable)
  • Is there a difference between my_variable = my_variable + 1 and my_variable += 1?
  • Can you do this with other operators? Is there a -=, *=, or /=?