The goal of this assignment is to familiarize you with conditionals, including both logical operations and relational operations.
Feature | Value |
---|---|
Asks user for at least two pieces of information | 2 |
Response says something about the programmer | 2 |
Response meaningfully related to information from the user | 2 |
No errors | 2 |
Correctly named files | 1 |
Comments throughout code | 2 |
At least one variable | 1 |
At least two operators | 2 |
Operation on a string | 1 |
Operation on a numeric type | 1 |
Interesting use of conditionals | 2 |
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
.
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
Create a file called interact.py
. We'll develop an interactive program in
this file that meets the following 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:
input()
function+
, -
, /
, and *
int
or float
str
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!
Make sure that your program is properly commented:
In addition, make sure that you have used good style. This includes:
For this lab you are required to submit the following files:
calculator.py
(remember to comment appropriately!)interact.py
(remember to comment appropriately!)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.