Overview

The goal of this assignment is to allow you to explore the basics of the Python programming language. To record your solutions and answers, create a new Jupyter Notebook titled Notebook 01 - Basic Syntax and Types.ipynb and use this notebook to complete the following activities and answer the corresponding questions.

Make sure you label your activities appropriately. That is for Activity 1, have a header cell that is titled Activity 1. Likewise, use the Markdown cells to answer the questions (include the questions above the answer).

This Notebook assignment is due Midnight Wednesday, September 9, 2015 and is to be done individually.

Activity 1: Formulas

For this activity, you are given the following three math formulas:

Formula 1: Volume of a Sphere

Formula 2: Volume of a Cylinder

Formula 3: Volume of Rectangular Pyramid

For each formula, you are to write a program that prompts the user for the appropriate input, perform the computation, and then print out the formatted result.

A transcript of the program for Formula 2 should go as follows:

What is the radius? 10
What is the height? 42
Volume of Cylinder with radius 10 and height 42 is 13194.69

Output results to two places after the decimal point.

Questions

After you have completed the programs above, answer the following questions:

  1. What happens if a user enters in non-numerical input or nothing at all? Why does this happen?

  2. Did you use ints or floats? Does it make a difference? Why?

Activity 2: Magic 8-Ball

For this activity, you are to implement a program that simulates a Magic 8-Ball by prompting the user for a question and then randomly printing one of the following outcomes:

  1. It is certain
  2. It is decidedly so
  3. Without a doubt
  4. Yes definitely
  5. You may rely on it
  6. As I see it, yes
  7. Most likely
  8. Outlook good
  9. Yes
  10. Signs point to yes
  11. Reply hazy try again
  12. Ask again later
  13. Better not tell you now
  14. Cannot predict now
  15. Concentrate and ask again
  16. Don't count on it
  17. My reply is no
  18. My sources say no
  19. Outlook not so good
  20. Very doubtful

A transcript of the program should go as follows:

What is your question? Will Notre Dame win the national championship this year?
Without a doubt

Hint: random.choice

Questions

After you have completed the program above, answer the following questions:

  1. Did you use a data structure in your program? If so, which one and why? Could you have used another one instead (which one)?

  2. Execute your program a few times. Is your Magic 8-Ball positive, neutral, or negative? If you wanted to make an overly pessimistic or negative Magic 8-Ball, what could you do to accomplish that without removing any positive or neutral answers?

Activity 3: Bug Hunting

For this activity, each of the following programs contains at least one bug. You are to identify the bugs and correct the programs.

Program 1

# Print list of points
x0, y0 = 0, 0
x1, y1 = 1, 1
points = [(x0, y0), (x1, y1)]
print 'Points:' + points

Program 2

# Convert Celsius to Fahrenheit
celsius    = 32
fahrenheit = celsius * 9/5 + 32
print 'Celsius ({}) = Fahrenheit ({})'.format(celsius, fahrenheit)

Program 3

# Convert miles to feet
miles = 10
feet  = 5,280
print '{} miles is {} feet'.format(miles, miles * feet)

Questions

After you have fixed the programs above, answer the following questions:

  1. Explain the process you used to identify and fix each program.

  2. Which bug was the hardest for you to identify and fix? Explain.

Submission

To submit your notebook, follow the same directions for Notebook00, except store this notebook in the notebook01 folder.