Project 3: Variables and Formatting

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

Exercises

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 a number. Assume that the number is a float(). Here's a snippet:

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

Your program should load input() two numbers and store them in variables a and b. Then it should perform calculations on those numbers. The output of the program should follow this example exactly given the same inputs:

Input a number for the variable "a"
23
Input a number for the variable "b"
32
a is 23.0
b is 32.0
23.0+32.0 = 55.0
23.0-32.0 = -9.0
23.0*32.0 = 736.0
23.0/32.0 = 0.71875
23.0%32.0 = 23.0
23.0<32.0 = True
23.0>32.0 = False
23.0==32.0 = False

Here are important rules to follow:

  1. No spaces between the numbers and the operators (i.e. 1+2)
  2. You must perform all of the operations listed above.
  3. I will test your code with random numbers, you must actually do the math!
  4. You must use either format() function, f-strings (or both).

A Web Calculator (Advanced)

For extra practice use the Jinja2 template engine to create a table with the results of your calculator. The styling of the table isn't relevant. I haven't taught you how to take input over the web yet, so place the input() lines at the top of your file. You will have to input the two numbers before you can go to the web page.

Here's an example of what the table should look like:

Operation Result
23.0+32.0 55.0
23.0-32.0 -9.0
23.0*32.0 736.0
23.0/32.0 0.71875
23.0%32.0 23.0
23.0<32.0 True
23.0>32.0 False
23.0==32.0 False

Here are the requirements:

  1. The header row is required.
  2. Style is optional (it can be plain and ugly)
  3. No spaces between the numbers and the operations
  4. Save your template in a file called project3.html

Turn In

  • ex6.py
  • ex7.py
  • ex8.py
  • ex9.py
  • ex10.py
  • project3.py
  • (optional) project3_adv.py
    • project3.html (Your Jinja2 template file)

Grading

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