Homework #3

Due: February 6, 2012Points: 100

For this homework, please put refinements for all your programs into one file called “refinements.txt” or “refinements.pdf”, and error journal entries for all your programs into one file called “errors.txt” or “errors.pdf”.

  1. (100 points) Write a program to compute the sum of the first n cubes (that is, each number from 1 to n raised to the third power, and the powers summed). Prompt the user to input n. Please do three versions of the program.
    1. (50 points) In the first version, you may assume that the user will enter a non-negative number. Your output is to be:
      Enter the number of cubes to sum: 10
      The sum of the first 10 cubes is 3025
      (The number in italics is what the user types; you are not to print it in italics, because the Python interpreter will echo it. Also, the “↵” simply indicates pressing ENTER or RETURN; you are not to print that, either.) Turn in your program in the file “sumcubesa.py”.
    2. (25 points) In the second version, you may assume that the user will enter a number, but it may be negative. If it is, you are to print
      You entered a negative number; you must enter a non-negative number
      instead of the second line. Turn in your program in the file “sumcubesb.py”.
    3. (25 points) In the third version, you may not assume the user will enter a number. If they do not enter a number, you are to print
      You did not enter a number; you must enter a non-negative number
      instead of the second line. Turn in your program in the file “sumcubesc.py”.

Extra Credit

Submit this program in the Extra Credit 3 area of SmartSite—not in the Homework 3 area.

(30 points) Recall the formula for the solutions to a quadratic equation y = ax2 + bx + c is:

First quadratic root
and
Second quadratic root
Write a program that reads in a, b, and c, checks that they are numbers, checks that b2−4ac is non-negative, and then computes the two roots. If any of the inputs are not numbers, or b2−4ac is negative, report an error and stop.


A PDF version is available here.
ECS 10, Basic Concepts of Computing
Winter Quarter 2012
\end{document}