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

[Back to Lab 2] [Back to CS 115 schedule]


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, in PyCharm, create a file called lab02.py in project cs115/lab02.
  2. Type in (or copy-paste) the following program exactly as written, substituting your name for the italicized text:
    """
    Program: CS 115 Lab 2
    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 ", square_area, ".", sep="")
    
    
    main()
  3. Execute the program several times to complete the table in Question 7 of your Moodle writeup.
  4. Continue to Part C.