Project 3: Variables and Formatting

In this project you'll take user input, perform a calculation and print formatted output.


You will turn in Exercises 6 through 10 with this project.

A Python Calculator

Write a Python program that prompts the user for input and reads two numbers. You can assume that the number will always be a valid float. Here's a snippet showing how to read the first number:

print ('Input a number for the variable "a"')
a = float(input())

Your program should input() two numbers and store them in variables a and b. Once the two numbers are read your program should generate an HTML document that contains a table. The table shows the result of doing various mathematical operations on the input.

For example, if the user enters 12 for a and 21 for b the HTML table you generate should look like this when you load it into the browser:

The output of your program must be a complete HTML document that looks like this:

<!DOCTYPE html>
    <title>Project 3</title>
      <!-- your table here -->

You can test your HTML by copy and pasting the HTML code into a file in your Cloud9 IDE. The “Preview” button in the IDE opens the file in the embedded browser.


  1. Your program and exercises must have docstrings
  2. Your program must generate a complete HTML document as shown.
  3. Your table must have a header row as shown
  4. There must be no spaces between the numbers and the operators (i.e. 1+2)
  5. You must perform all of the operations shown.
    1. I will test your code with random numbers, you must actually do the math!
  6. Your program must be submitted in a file called

A Web Calculator (Optional)

Most programs that generate HTML send it directly to the browser. That's what flask is used for! Like last week, for extra practice you should convert the basic project into a web-based version. Start with the following flask code:

from flask import Flask 
app = Flask(__name__)
# Read variables and compute your template here... 
print ('Input a number for the variable "a"')
a = float(input())
def index() :
    # Replace the line below with one that returns your HTML
    return "Put your HTML here"
if __name__ == '__main__' :'', port=8080, debug=True)

Turn In

  • (optional)


  • 5 points for the exercises
  • 5 points for correctness of your submission (filenames, formatting)
  • 10 points for a correct program.