CP1: imported math for pi, used the area formula

A value is some object that exists, whereas a name is a reference to
that value. An example where it is important to distinguish between a
name and the value it represents is any reference to time. Sometimes
generalization is acceptable ("I don't have time") but often the actual
amount matters and so we care about the value, not the name itself.

Variables are useful in programming because their values are able to be
changed, by definition (variables can vary). This is useful because we
can use variables to parameterize our code, allowing for easier modification
and improvement or expansion. They can also make code more readable,
even without documentation because effective naming of variables allows
someone (even one who didn't write the specific code referenced) to see
the variable names and hopefully understand what the values mean and how
they are used in the program, for example, using "ballSpeed" vs "x".
This commit is contained in:
Pat Wick 2023-07-16 20:35:32 -04:00
parent 1afc5bf40d
commit dda8666763
3 changed files with 18 additions and 3 deletions

View File

@ -1,6 +1,9 @@
# circle_area.py
# --------------
# By MWC Contributors
import math
print("This program will calculate the area of a circle.")
radius = float(input("What is the circle's radius? "))
area = math.pi * radius * radius
print(area)

View File

@ -2,6 +2,6 @@
# ------------
# By MWC contributors
my_name ="Chris"
my_name = input('What is your name? ')
greeting = "Hello, " + my_name
print(greeting)

View File

@ -5,7 +5,19 @@
from turtle import *
def triangle(side_length):
pass
forward(side_length)
right(120)
forward(side_length)
right(120)
forward(side_length)
right(120)
def rectangle(height, width):
pass
forward(width)
right(90)
forward(height)
right(90)
forward(width)
right(90)
forward(height)
right(90)