CS 115 Lab 2, Part B: Compute the area of a square

[Back to lab instructions]


The Big Picture

The instructions below will help you write a program that:

You should be able to trace through the execution of this program and understand how the values of the variables change after each statement.


Instructions

  1. First, create and open a new Python source code file:
  2. In the lab02bcd.py window, copy-paste the following program exactly as written, substituting your name for the italicized text:
    """
    Program: CS 115 Lab 2b/c/d
    Author: Your name
    Description: This program will compute the area of a square,
        given the side length.
    """
    
    
    def main():
        # Get the side length
        length = float(input('Enter a numeric value: '))
    
        # Compute the area of the square
        square_area = length * length
    
        print("The area of a square with side length ", length,
              " is ", round(square_area, 3), ".", sep="")
    
    
    main()
    
  3. Save your file:
  4. Run your program:
  5. Run the program twice to complete the table in Question 5 of your Moodle writeup.
  6. Run the program one more time, and type something that isn't a number. Answer Question 6 in your writeup.
  7. Continue to Part C.