What is a Variable?

1. Let x represent.

Predict the output of the following program and then run it to see what happens.

2. Hello, my name is...

In the program above, x is called a variable. A variable doesn’t have to be just a single letter! Can a variable have the same name as you? Can it contain spaces? Modify and run the above program to find out!

3. The little things matter!

The following program was created to display the perimeter and area values of a square that has a given side length. Run the program to confirm that it contains an error and then edit the code to fix the error. Check your work by running the program again.

4. Square up.

Modify the code of your corrected program above to display the perimeter and area values for a square with a side length of 250 units.

5. Round and round.

The following program displays the diameter (d) of a circle based on its circumference (C). Study the program and then run it to see the diameter of a circle that has a circumference of 87 units.
Next, add a sixth line to the program that contains the code print(round(d)). Run the program again. What does the round() command do?

6. What's the point?

In the program above, add a seventh line that contains the code print(round(d, 2)). What does it do? Run the program using a few different values for C to confirm your answer.

7. Your turn.

The formula for the area of a circle is A = πr². Use the editor below to write and run a program that calculates and displays the area of a circle based on the value of its radius. Be sure to

  • use variables to represent the circle’s radius and area, and start with a radius value of 8.5.
  • have the program’s output rounded to one decimal place.
  • test your program using at least three other radius values.

  
HINT: You can approximate π with 3.14.

Previous

Displaying Results

Next

Working with Variables