Learning Objectives

Through readings, lecture and labs, it is expected that you are doing work and seeking help to keep pace with the below objectives:

Variables, input, output, assignment.

You should be achieving much greater competance with this topic's objectives from last week.

Arithmetic operations
You should be comfortable with:

  • Using the following arithmetic operators in your Python programs, and correctly applying order of operations:
    • + (addition)
    • - (subtraction)
    • * (multiplication)
    • / (floating-point division)
    • // (integer division)
    • % (modulus or remainder)
    • ** (exponentiation, a.k.a. taking a number to a power)
Definite (for) loops
You should be comfortable with:
  • Using for loops to execute blocks of code repeatedly
  • Tracing the sequence of values taken by a loop counter variable
  • Using range to manipulate a loop counter

Required Reading


Supplemental Materials

We all need alternative presentations of the concepts from time to time. The following resources are optional. If something seems unclear after class, or the pratice questions seem hard for you, then explore these topics more using the resources below.

Arithmetic operations
Definite (for) loops

Practice

For all these exercises, I recommend you try them on paper and then test them out with PythonTutor.

Exercise 1

Write what this code produces, exactly. Be very careful with whitespace and the newlines.

a = 11
b = 4
c = a // b 
d = a % b
print(a,b, sep='/', end=" => ")
print(c,d, sep=' remainder ', end="?!")

Exercise 2

Write what this code produces, exactly. Be very careful with whitespace and the newlines.

a = 10
b = 7
print(a % b, a+b, a*b, "a-b", "10"+"7", sep="\n")

Exercise 3

Write what this code produces, exactly. Be very careful with whitespace and the newlines.

seaw = 'SeaWolves'
print('Go', seaw, end='!\n!')
print(seaw + ' Rock')

Exercise 4

Write what this code produces, exactly. Be very careful with whitespace and the newlines.

k = 0
for i in range (1 , 10, 2):
   print(i)
   k = k + i
print (k)

Exercise 5

Write a piece of code that produces the following input/output behavior. Text that is italics and underlined are user input.

Enter an integer: 100
Sum of squares of numbers 1--100 is: 338350
Here is a sample answer, when you think you have solved it. (Don't cheat yourself and look early).