EECS 12 Summer 2006 Homework 1

General Instructions

Please place your programs in seperate files named as described in the problem. Improperly named programs will not count. Turn in your files by placing them in the dropbox. Please be mindful of the late policy.

Grading

Correct80%
Commented10%
Attempted10%

Problems

Problem 0: 25 points

Create a python program named fruittest.py that defines the following functions:

  1. isApple(fruit): returns true if fruit is either 'apple' or 'Apple'
  2. isOrange(fruit): returns true if fruit is either 'orange' or 'Orange'
  3. isAppleOrOrange(fruit): returns true if fruit is an apple or an orange

Be certain to provide function documentation strings

Problem 1: 25 points

Create a python program named fruitstand.py that does the following:

  1. imports fruittest
  2. asks the user for a fruit
  3. if the user's fruit is an apple or an orange, tell the user, "Here is your bag of xs!" where x is the user's fruit.
  4. Otherwise, tell the user, "Here is your box of xs!" where x is the user's fruit

Problem 2: 50 points

Create a python program named calc.py that acts as a very simple calculator.

  1. It will support the operations: +, -, log, sqrt
  2. It will perform only one operation and then exit
  3. It will ask first for operation, and then for arguments, depending on how many arguments the operation takes
  4. Define and use two functions getOneArg() and getTwoArgs() that ask the user for and return 1 and 2 arguments, respectively.
  5. Define and use a function result(res) that prints out the result as shown below
  6. All operations should be done in floating point.
  7. If the user enters an operation that is not supported, it will print out the message "Invalid Operation!"

Here is a sample set of interactions (with ######## as the break in between different runs of the program):

Operation (+, -, log, sqrt): +
Argument 1: 5
Argument 2: 6
Result: 11.0
#######
Operation (+, -, log, sqrt): - 
Argument 1: 5
Argument 2: 6
Result: -1.0
#######
Operation (+, -, log, sqrt): log 
Argument: 5
Result: 1.60943791243
#######
Operation (+, -, log, sqrt): sqrt 
Argument: 6
Result: 2.44948974278
#######
Operation (+, -, log, sqrt): frog
Invalid operation!