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:
- Asks the user to enter the side length of a square
- Calculates the area of the square
- Prints the calculated area.
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
- First, in PyCharm, create a file called lab02.py in project cs115/lab02.
- 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()
- Execute the program several times to complete the table in Question 7 of your Moodle writeup.
- Each time you execute the program, you will be prompted to enter a value.
When that happens, type in the information in a row of the Input Value column,
exactly as it appears, then press ENTER.
- Record the value that your program reports for the area of the square.
- Continue to Part C.