Assignment 2: Conditionals

Overview

The goal of this assignment is to familiarize you with conditionals, including both logical operations and relational operations.

Grading Rubric

FeatureValue
Asks user for at least two pieces of information2
Response says something about the programmer2
Response meaningfully related to information from the user2
No errors2
Correctly named files1
Comments throughout code2
At least one variable1
At least two operators2
Operation on a string1
Operation on a numeric type1
Interesting use of conditionals2

Part 1: A simple calculator

For this part of the assignment you will write a (very) simple calculator which can (only) add, subtract, and multiply two integers. It's a good idea to work on this during your LC meeting. Create a week2 folder and add a file called calculator.py.

Specification

Here is an example of a sample run. The first three lines are the inputs.

  What is the first operand?
  > 31
  What is the second operand?
  > -1
  What is the operation (+,-,*)?
  > +
  31 + -1 = 30

Note that if you pass an argument to input, you can specify the "prompt" string (e.g., input("> ")). It may also be helpful to consider the following example showing how to check the contents of a string:

  >>> op = '/'
  >>> op == '/'
  True
  >>> op == '+'
  False

Part 2: An Interactive Program

Create a file called interact.py. We'll develop an interactive program in this file that meets the following specification.

Specification

For full credit, your program must do each of the following:

In addition, the way in which your code accomplishes the above must satisfy the following requirements:

Example

The previous section outlines the requirements. You're strongly encouraged to exercise your creativity in satisfying them! The following is one example of a program that satisfies the (minimum) requirements. (Yes, you'll have to take our word for it that the underlying code satisifes the implementation requirements... note the distinction between what something is doing and how it does it!)

  What is your name?
  > Cecil
  Hi Cecil! It is nice to meet you. My name is Prof. Osborn. I've been with Pomona College since 2018.
  Pick a number
  > 47
  Great! Did you know 47 + 2 = 49, and 47 * 2 = 94?
  I also like videogames and electronics projects.  Do you know how to solder?
  > Yes
  Great! That's all for now. Bye Cecil!

Coding Style

Make sure that your program is properly commented:

In addition, make sure that you have used good style. This includes:

Submission

For this lab you are required to submit the following files:

Note that you will lose points if your submitted files are incorrectly named or if they are submitted separately. Please double check that you got this right.