Department of Mathematics, Computer Science, and
                Statistics
St.
                Lawrence University
Zonohedron
 

What is this object?

...

Links
Overview
Schedule
Grading Info
Class Notes

 

CS 140: Introduction to Computer Programming


HOMEWORK #1
due Friday, Sept 7 by 5:00pm

Guidelines for completing and submitting homework
Refer to the first two paragraphs on the Grading Info page for all the details. (Be sure to read these paragraphs before starting on your first assignment.)  Briefly, you may not collaborate with your classmates in any way while writing homework programs—experience has shown that this policy is an unfortunate necessity for our course.  Please abide by it.  However, you may certainly consult Spencer on Thursday evenings or Dr. V on Friday afternoons as you create your programs.  Other QRC mentors may also be able to help out, depending on their experience with Python.  Once you have completed your program, or made as much progress as possible, email your program as an attachment to svandervelde@stlawu.edu.

Assignment
To begin, create a new document in Komodo and include these comments at the top
# Your full name
# Homework #1, Sept 7, 2012
# Individuals providing assistance, if any

Then save your file using the format LastNameHW1.py.  (Thus I would name my program VanderveldeHW1.py.)

Now write a program that performs the tasks listed below. (You will need to choose variable names as you go; use a single lower case word for each.)  Your program should include at least one elif statement and at least one else statement.

  • Print an opening remark about how the user needs to get arithmetic practice.
  • Choose a random three-digit number, and announce this fact to the user.  (Without revealing the secret number at this point.)
  • Ask the user to input their own three-digit number.
  • Compute this sum, storing the value in a variable called total.
  • Print a sentence displaying this sum.
  • Ask the user to deduce the secret number and input its value.
  • Make a response depending upon whether the answer was correct and also based on how large the secret number was, as follows:
  • (A) If the secret number was 500 or more and the answer was correct, provide a very positive response.
  • (B) Meanwhile, if the secret number was less than 500 and the answer was correct, provide mild praise.
  • (C) If the secret number was 500 or more and the answer was incorrect, state that the answer was wrong, but hey, it was a tough question.
  • (D) Finally, if the secret number was less than 500 and the answer was incorrect, give the user a hard time for missing such an easy question.
  • Now announce to the user the value of the secret number and provide two numerical facts regarding this number: the remainder when the number is divided by 13 and the cube of the number.