Computer Science I for majors by James Tam

Return to the course web page

CPSC 231: Mini-Assignment 2B

Due Friday Oct 14 at 4 PM

New Concepts to be applied for the assignment

Description:

Write a program that will prompt the user for a base and an exponent/power. For exponents of zero or larger the program will  determine the result of raising the base to the specified power. For exponents larger than zero a Python loop will be used to calculate the result. The program should then display the base, power and the result e.g. "2 raised to the power 3 results in 8". Entry of a negative exponent should result in a helpful error message e.g. "The exponent cannot be less than zero." Due to hardware limitations it's expected that your program may run more slowly (if at all)  for very large calculations. For simplicity you can assume that the base and exponent will be integer inputs.

  1. Prompts (and gets input) for the base: Worth 0.5 grade points.
  2. Prompts (and gets input) for the power: Worth 0.5 grade points.
  3. Handles the error case (power less than zero) by displaying a helpful error message: Worth 0.5 grade points.
  4. Correctly 'calculates' and displays the result for the case where the power is zero: Worth 0.5 grade points.
  5. Correctly calculates and displays the result for the case where the power is greater than zero (loop employed as previously specified): Worth 2 grade points.

A student that completes the above 5 features will receive a grade point of: 0.5 + 2 + 0.5 + 0.5 + 0.5 = 4.0 or the equivalent of an 'A'.

Marking spreadsheet

Points to keep in mind:

  1. Due time: All assignments are due at 4 PM on the due dates listed on the course web page.  Late assignments or components of assignments will not be accepted for marking without approval for an extension beforehand. What you have submitted in D2L as of the due date is what will be marked.
  2. Extensions may be granted for reasonable cases by the course instructor with the receipt of the appropriate documentation (e.g., a doctor's note). Typical examples of reasonable cases for an extension include: illness or a death in the family. Cases where extensions will not be granted include situations that are typical of student life: having multiple due dates, work commitments etc. Tutorial instructors (TA's) will not be able to provide extension on their own and must receive permission from the course instructor first. (Note: Forgetting to hand your assignment or a component of your assignment in does not constitute a sufficient reason for handing your assignment late).
  3. Method of submission: You are to submit your assignment using D2L [help link]. Make sure that you [check the contents of your submitted files] (e.g., is the file okay or was it corrupted, is it the correct version etc.). It's your responsibility to do this! (Make sure that your submit your assignment with enough time before it comes due for you to do a check).
  4. Identifying information: All assignments should include contact information (full name and student ID number) at the very top of your program in the class where the 'main()' function/method resides.
  5. Collaboration: Assignments must reflect individual work, group work is not allowed in this class nor can you copy the work of others.  For more detailed information as to what constitutes academic misconduct (i.e., cheating) for this course please read the following [link].
  6. Execution: programs must run on the computer science network running Python 3.x. If you write you code in the lab and work remotely using a remote login program such as Putty or SSH. If you choose to install Python on your own computer then it is your responsibility to ensure that your program will run properly here. It's not recommended that you use an IDE for writing your programs but if you use one then make sure that you submit your program in the form of text ".py" file or files
  7. Use of pre-created Python libraries: unless otherwise told you are to write the code yourself and not use any pre-created functions from the Python libraries. For this assignment acceptable functions include: print(), input() and likely str(). Since you are to apply repetition to calculate the exponent it should be self-evident why the use of pre-created math function/method to perform this task is prohibited.