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.

Types (str, int, float)
You should be experimenting and getting comfortable with:
  • Deciding what data type is appropriate for a particular type of data (for example, a person's name, a number of students, an amount of money...)
  • Figuring out the data types of variables in Python programs by analyzing the source code.
  • Defining and using variables for numeric data.
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)
  • Using the sqrt() function and pi constant from the math library

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.

Types (str, int, float)
Arithmetic operations

Practice

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

Exercise 1

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

An integer value for a: 4
An integer value for b: 2
a to the b is: 16
The square root of a is: 2.0
Here is a sample answer, when you think you have solved it. (Don't cheat yourself and look early).

Exercise 2

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 3

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")