Writing Simple Programs

In this topic, we’ll be writing a computer program in Python.

Make sure you are familiar with how to use the IDLE development program, or just use your favorite development tools that you have discovered on your own (text editors, or other IDEs, if that is your choice.)

Your Assignment

I would like you to write an interactive Python calculator program that does the following:

  1. Print a friendly message prompting the user an arithmetic expression, which is then evaluated.
  2. Print the value of the evaluated expression.
  3. Include a definite loop so that the user can perform 100 different expression calculations.
  4. Your program should print a friendly introduction (one line is fine) that explains what it does when the program first runs.
  5. Your program should be written inside a function called main(), as we’ve explained in class.

Note: to quit early, just allow the user crash the program by typing a bad expression, or simply closing the window that the calculator program is running in. You’ll learn better ways of terminating interactive programs in later on.

Hint: All the parts you need to make a calculator should already be known to you from lecture! Do not over-think your solution!


Your program should look similar to this, though your arithmetic expressions may be different:

Enter a mathematical expression: 1 + 1
1 + 1 = 2
Enter a mathematical expression: 3 * 3.1459
3 * 3.1459 = 9.4377
Enter a mathematical expression:

Submission Requirements

Your file is required to be named lab_writing_programs.py.

Please read and follow the Submission Requirements to avoid point deductions specified below.


The following is the grading rubric for this lab to be used by the course graders. The lab is worth 100 points.

Note: There may be additional criteria for grading, this is just a summary of the major rubric items.

Grading Rubric
Type Description Point Loss (Max)
SyntaxError Exceptions A program that doesn’t even start due to syntax errors. -30
Docstrings Missing proper lab header (e.g. no name, lab section, etc) -10
main() Your program should have main() as the first-called function -10
PEP 8 Style Egregious problems with your code styling -10
Incorrect Filename Follow the submission instructions -5
Commenting Insufficient or excessive comments -5
  [Lab Specific]  
Looping Doesn’t do a constant number of loops (like 100) -15
Iterations Doesn’t use the correct number of iterations in the for loop based on user input -15

Extra Credit

Extra credit work must be submitted in what would be your original submission file for the assignment. All extra credit code must be clearly commented in order to receive any points.

  • +5 points

    Can you “pretty print” the calculation, instead of just printing the result? For example, printing a result of "3 * 4 = 12", instead of "12".

  • +5 points

    The assignment asks that you let your loop run, say 100 times. Can you change it so the user can tell the program how many calculations to evaluate?